Java how to get the last two characters in a string

http‮//:s‬www.lautturi.com
Java how to get the last two characters in a string

To get the last two characters of a string in Java, you can use the substring() method of the String class. This method takes two arguments: the starting index of the substring (inclusive), and the ending index of the substring (exclusive).

For example, to get the last two characters of a string, you can use the following code:

String str = "Hello, world!";
String lastTwo = str.substring(str.length() - 2);
System.out.println(lastTwo); // Output: "d!"
Created Time:2017-10-10 11:01:46  Author:lautturi