
How we can find out the last character of array in java program ?

Example:-
public class MyStringExample {
public static void main(String[] args) {
String str = "facebook";
char chars[] = str.toCharArray();
int charPosition = chars.length - 1;
System.out.println(chars[charPosition]);
}
}
Output
K
Description:- The given Example find out the last character of a string. We have a created a class named MyStringExample. In the main method, we have declared a string variable â??facebookâ??.now next step we will be used method â??int charPosition = chars.length â?? 1â??
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.