Java String isEmpty

The java string isEmpty() method checks if this string is empty. It returns true, if length of string is 0 otherwise false.
The isEmpty() method of String class is included in java string since JDK 1.6.

Signature

The signature or syntax of string isEmpty() method is given:

public boolean isEmpty()

Returns

true if length is 0 otherwise false.

Since

1.6

Java String isEmpty() method example

public class IsEmptyExample{  
public static void main(String args[]){  
String s1="";  
String s2="catchmecoder";  
System.out.println(s1.isEmpty());  
System.out.println(s2.isEmpty());  
}}

Output:

true
false

Java String join

The java string join()method returns a string joined with given delimiter. In string join method, delimiter is copied for each elements.
In case of null element, "null" is added. The join() method is included in java string since JDK 1.8.
There are two types of join() methods in java string.

Signature

The signature or syntax of string join method is given :

public static String join(CharSequence delimiter, CharSequence... elements)  
and  
public static String join(CharSequence delimiter, Iterable elements)

Parameters

delimiter: char value to be added with each element
elements:char value to be attached with delimiter

Returns

joined string with delimiter

Throws

NullPointerException if element or delimiter is null.

Since

1.8

Java String join() method example

public class StringJoinExample{  
public static void main(String args[]){  
String joinString1=String.join("-","welcome","to","catchmecoder");  
System.out.println(joinString1);  
}}         

Output:

welcome-to-catchmecoder

Java String length

The java string length() method length of the string. It returns count of total number of characters. The length of java string is same as the unicode code units of the string.

Signature

The signature of the string length() method is given:

public int length()

Specified by

CharSequence interface

Returns

length of characters

Java String length() method example

public class LengthExample{  
public static void main(String args[]){  
String s1="catchmecoder";  
String s2="android";  
System.out.println("string length is: "+s1.length());  //12 is the length of catchmecoder string  
System.out.println("string length is: "+s2.length());   //7 is the length of android string  
}}      

Output:

string length is: 12
string length is: 7