Languages
[Edit]
EN

Java - get last char from string

11 points
Created by:
AnnLen
9180

Problem:

How to get last character from string in java?

I have: "abc"
I want: "c"
String str = "abc";
System.out.println(str); // abc
// ..
System.out.println(str); // c

Solution:

String str = "abc";
System.out.println(str.charAt(str.length() - 1)); // c

Docs:
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#charAt-int-

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join