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

Local vs Instance vs Class vs Reference variable in Java

In Java we have 4 type of variables :- Local Variable Instance Variable Class variable Reference variable Java developers often get confused while using these terms, let us understand the difference between them in detail : Local Variable Local variables are those which are defined inside a block, method or constructor. These variables get destroyed … Read more

Value of PI in Java

PI value in mathematics is a very important value used in number of formulas. In java value of PI can be obtained through Math class of java.lang package. Math.PI is a double constant whose value = 3.141592653589793 Let us look at a program to calculate area of circle using Math.PI Output

Declaration vs Instantiation vs Initialization

Declaration, Instantiation and Initialization are very confusing terms in Java. Let us clear their meanings with example : Declaration A variable is said to be declared when we give name to variable and associate it with a class. Example :- Student stu; (here Student is a class) Instantiation Instantiation means we are creating an object … Read more