freetimestudys@gmail.com          +91-7097633380
  Login Here                        

Split(String):-

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  freetimestudy";
String[] str1=str.split(" ");
for (int i=0;i{
System.out.println(str1[i]);
}
}
}

intput and output

output:hi,,freetimestudy

Split program

class Test
{
public static void main(String[] args)
{
String str="hi,freetimestudy";
String[] str1=str.split(",");
for (int i=0;i{System.out.println(str1[i]);
}
}
};

intput and output

output:hifreetimestudy

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="   venkat  ";
System.out.println(str.length());
System.out.println(str.trim());
System.out.println(str.trim().length());
}
}

intput and output

outpuit:8,,venkat,6