How do I get the last character of a string?
public class Main
{
public static void main(String[] args)
{
String s = "test string";
//char lastChar = ???
}
}
How do I get the last character of a string?
public class Main
{
public static void main(String[] args)
{
String s = "test string";
//char lastChar = ???
}
}
The other answers contain a lot of needless text and code. Here are two ways to get the last character of a String:
char
String
Output should be:
Happy coding!
Try this:
The code:
The output: