Professional Documents
Culture Documents
String In-Build Methods
String In-Build Methods
Program of length(),isEmpty,charAt,indexOf
package String;
//Length()
int l = str.length();
System.out.println(l);
///charAt
String s1="laptop";
for(int i=0;i<s1.length();i++)
char c = s1.charAt(i);
System.out.println(c);
///isEmpty()
String s2="";
if(s2.isEmpty())
else
System.out.println(s3);
}
2. Progarm of Uppercase,LowerCase,contaons,startsWith,endsWith
package String;
//LowerCase
System.out.println(lowerCase);
//UpperCase
System.out.println(UpperCase);
//Contains
String s1="Yamaha";
String s2="Yamaha";
Boolean b = s1.contains(s2);
System.out.println(b);
Boolean k = s1.startsWith("Y");
Boolean k1 = s1.endsWith("a");
if(k==true)
}
if(k1==true)
3.Program of equals,concat,replace,replaceAll,split,trim
package String;
//check equals
String s1="Yamaha";
String s2="Yamaha";
Boolean b = s1.equals(s2);
System.out.println(b);
//Combine
String s3="Yamaha";
System.out.println(combined);
String word="Weather";
System.out.println(word.replace("Weather","Hot"));
//split
String sentence=" yamaha,KTM,TVS,Honda,Hero";
for(String a : splitSentence)
System.out.println(a);
System.out.println(sentence.trim());