Google News
logo
Java Split
String Split
String[] split(delimiter): This method is useful to break a string into pieces at places represented by delimiter.

String Split program
class Test 
{ 
public static void main(String[] args) 
{ 
String str="hi freetimelearn"; 
String[] str1=str.split(" "); 
for (int i=0;i<str.length;i++){ 
System.out.println(str1[i]); 
} 
} 
}
Output :
hi,freetimelearn
Split program
class Test 
{ 
public static void main(String[] args) 
{ 
String str="hi,freetimelearn"; 
String[] str1=str.split(","); 
for (int i=0;i{<str.length;i++){
System.out.println(str1[i]); 
} 
} 
};
Output :
hifreetimelearn
String trim():
This method removes spaces from the beginning and the ending of the string.
Example: String str1 =  hello welcome;
System.out.println(str1.trim());
Output: hello welcome
trim pagram
class Test 
{ 
public static void main(String[] args) 
{ 
String str=" ramana"; 
System.out.println(str.length());
System.out.println(str.trim());
System.out.println(str.trim().length());
} 
}
Output :
8,ramana,6