Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 4

1.

Program of length(),isEmpty,charAt,indexOf

package String;

public class StringMethod {

public static void main(String[] args) {

//Length()

String str="Bike are good company for youngester";

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())

System.out.println("the string is empty");

else

System.out.println("the string is not empty");

///indexOf particular string

int s3= s1.indexOf("t",2);

System.out.println(s3);
}

2. Progarm of Uppercase,LowerCase,contaons,startsWith,endsWith

package String;

public class StringMethod2 {

public static void main(String[] args) {

String s ="Laptop name is Dell";

//LowerCase

String lowerCase= s.toLowerCase();

System.out.println(lowerCase);

//UpperCase

String UpperCase= s.toUpperCase();

System.out.println(UpperCase);

//Contains

String s1="Yamaha";

String s2="Yamaha";

Boolean b = s1.contains(s2);

System.out.println(b);

//Star with and end with

Boolean k = s1.startsWith("Y");

Boolean k1 = s1.endsWith("a");

if(k==true)

System.out.println("K start with same word");

}
if(k1==true)

System.out.println("a ends with same word");

3.Program of equals,concat,replace,replaceAll,split,trim

package String;

public class StringMethod3 {

public static void main(String[] args) {

//check equals

String s1="Yamaha";

String s2="Yamaha";

Boolean b = s1.equals(s2);

System.out.println(b);

//Combine

String s3="Yamaha";

String s4=" and TVS ";

String combined= s3.concat(s4);

System.out.println(combined);

//replace and replace All

String replace ="Jailer is not a higest crossing movie";

String newSentence= replace.replaceAll("not", "");

String word="Weather";

System.out.println(word.replace("Weather","Hot"));

//split
String sentence=" yamaha,KTM,TVS,Honda,Hero";

String[] splitSentence= sentence.split(",");

for(String a : splitSentence)

System.out.println(a);

//trim remove the extra space

System.out.println(sentence.trim());

You might also like