Answers for "how to select the last two characters of a string in java"

1

checking last 4 character of string java

Get last 4 characters
String input = "123456789";     //input string
String lastFourDigits = "";     //substring containing last 4 characters
 
if (input.length() > 4) 
{
    lastFourDigits = input.substring(input.length() - 4);
} 
else
{
    lastFourDigits = input;
}
 
System.out.println(lastFourDigits);
Posted by: Guest on October-18-2021
0

str.substring last 2 java

String substring = str.length() > 2 ? str.substring(str.length() - 2) : str;
Posted by: Guest on September-19-2020

Code answers related to "how to select the last two characters of a string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language