source file name: stringdemo2.java
class stringdemo2
{
public static void main(String as[])
{
System.out.println("string demo program");
System.out.println("upper case conversion: "+"One".toUpperCase());
System.out.println("lower case conversion: "+"Two".toLowerCase());
String str1="well come";
String str2="hello";
System.out.println("replacing string "+str1.replace('e','a'));
System.out.println("length of string before "+str2.length());
System.out.println("replacing string "+str2.trim());
System.out.println("length of string after "+str2.length());
System.out.println("equal strings: "+"Wel Come".equals("wel come"));
System.out.println("equal strings: "+"Wel Come".equalsIgnoreCase("wel come"));
System.out.println("char at int value "+" dbj college".charAt(3));
String str="dbj college";
System.out.println("index no at char value: "+str.indexOf('j'));
System.out.println("concatenation of 2 strings "+"suman".concat("patil"));
System.out.println("concatenation of 2 strings "+"dbj college".substring(str.indexOf('c')));
System.out.println("concatenation of 2 strings "+"dbj college".substring(4,7));
System.out.println("comparasion: "+"aba".compareTo("baba"));
System.out.println("comparison: "+"shubham".compareTo("kavita"));
System.out.println("comparison: "+"aba".compareToIgnoreCase("Aba"));
System.out.println("value= "+String.valueOf(10));
stringdemo2 strdemo1=new stringdemo2();
System.out.println("value= "+String.valueOf(strdemo1));
String p="101";
System.out.println("value= "+p.toString());
StringBuffer sb1=new StringBuffer(str);
StringBuffer sb2=new StringBuffer("DBJ COLLEGE");
System.out.println("capacity string "+sb1.capacity());
System.out.println("length string "+sb1.length());
System.out.println("append string "+sb1.append(" chiplun"));
System.out.println("delete string "+sb1.delete(4,11));
System.out.println("delete string "+sb1.insert(4,"family"));
System.out.println("reverse string "+sb2.reverse());
}
}
output:
D:\JavaPrograms\Misc>java stringdemo2
string demo program
upper case conversion: ONE
lower case conversion: two
replacing string wall coma
length of string before 5
replacing string hello
length of string after 5
equal strings: false
equal strings: true
char at int value j
index no at char value: 2
concatenation of 2 strings sumanpatil
concatenation of 2 strings college
concatenation of 2 strings col
comparasion: -1
comparison: 8
comparison: 0
value= 10
value= stringdemo2@f9f9d8
value= 101
capacity string 27
length string 11
append string dbj college chiplun
delete string dbj chiplun
delete string dbj family chiplun
reverse string EGELLOC JBD
0 Comments
Post a Comment