Oop’s Using java


public static void main(String args[]){


Download 0.74 Mb.
bet11/12
Sana15.11.2023
Hajmi0.74 Mb.
#1775298
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
OOP’s Using JAVA Module 2

 public static void main(String args[]){

String s1=“ bharath ";

System.out.println(s1);

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

String s2=“bharath”;

System.out.println(s2.indexOf(‘a’));

System.out.println(s2.lastIndexOf(‘a’));

System.out.println(s2.toUpperCase());

String s3=“BHARATH”

System.out.println(s3.toLowerCase());

String s4=“rathanIt”;

System.out.println(s4.replace(‘r’,’R’));

System.out.println(s4.substring(2));

System.out.println(s4.substring(2,5));

String s5=“Durga”

String S6=s5.concat(“software”);

System.out.println(s6);

}

}

String vs StringBuffer String is a Immutable and StringBuffer is mutable

String

class string{

 public static void main(String args[]){

String s= new String(“Durga”);

s.concat(“software”);

System.out.println(s);//Durga

}

}

String Buffer

class stringBuffer{

 public static void main(String args[]){

StringBuffer sb= new StringBuffer(“Durga”);

sb.append(“software”);

System.out.println(sb);//Durgasoftware

}

}

StringBuffer

Example of “String Buffer”

class StringBuffer{

public static void main(String args[]){

StringBuffer sb=new StringBuffer("Hello ");

sb.append("Java");

System.out.println(sb);

StringBuffer ab=new StringBuffer(“abcdef");

ab.insert(2,“xyz");

System.out.println(ab);

StringBuffer pb=new StringBuffer(“ILOVEU");

pb.replace(1,5,“HATE");

System.out.println(pb);

StringBuffer cb=new StringBuffer(“abcdef");


Download 0.74 Mb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   12




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling