• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
October 13, 2022 |1.4K Views

Java program to find the first and last character of a string

  Share  1 Like
Description
Discussion

In this video, we will write a Java Program to find the first and last character of a string. 

We have covered the following approaches: 
1. Using String.charAt() method. 
2. Using String.toCharArray() 

Method 1: Using String.charAt() method: In this method, we will access the first the last character of a string using String charAt() method, and by passing the first index value i.e. 0 and last index value i.e.: length of String - 1. 

Method 2: Using String.toCharArray() method: toCharArray() string method is used to convert String into character array. From the generated character array, we can easily get the first and last character using the same concept as in method 1.

Java Program to find the first and last character of a string
https://www.geeksforgeeks.org/how-to-find-the-first-and-last-character-of-a-string-in-java/