stripTrailing() method of String class

stripTrailing() method has been introduced in String class of Java 11. It is used to remove all the trailing white space characters from the string and return the remaining string. It means it removes white spaces that come at the end of string. If the string only contains the white spaces then an empty string is returned. Let us … Read more

stripLeading() method in String class

stripLeading() method has been introduced in String class of Java 11. It is used to remove all the leading white space characters from the string and return the remaining string. It means it removes white spaces that comes at beginning of the string. If the string only contains the white spaces then an empty string … Read more

strip() method in String class

In Java 11 a new method strip() has been introduced in String class. It is used to remove all the trailing and leading white space characters from the string. strip() method returns the string after removing these white spaces. If the string only consists of white spaces then an empty string is returned. Let us … Read more

isBlank() vs isEmpty() in String class Java

isBlank() is a new method introduced in String class in Java. By naming isBlank() and isEmpty() methods look similar to each other, but there is a slight difference between them – isBlank() returns true for the string having only white space characters whereas isEmpty() will return false for such strings. Let us understand the difference … Read more

NumberFormatException in Java and how to prevent it

NumberFormatException occurs in Java when we are trying to convert string into some numeric type but string is not in the correct format. It usually occurs when we parse string to integer, double, long etc datatypes but string is not present in correct format. Let us see an example code : Output Since ‘123a’ cannot … Read more