Oct
17
class TestString2{
public static void main(String args[]){
String s1=”ABC”;
String s2=new String(“ABC”);
String s3=”abc”;
String s4=” AB C “;
String s5=”abcabcabc”;
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
System.out.println(s1.equalsIgnoreCase(s3));
System.out.println(s4.equalsIgnoreCase(s3));
System.out.println(s1.length());
System.out.println(s4.length());
System.out.println(s4.trim().length());
System.out.println(s3.toUpperCase());
//s3=s3.toUpperCase();
System.out.println(s3);
System.out.println(s1.toLowerCase());
System.out.println(s3.charAt(1));
System.out.println(s3.indexOf(‘b’));
System.out.println(s5.indexOf(‘b’));
System.out.println(s5.lastIndexOf(‘b’));
System.out.println(s5.indexOf(‘b’,5));
System.out.println(s5.indexOf(“ab”));
System.out.println(s5.indexOf(“ab”,3));
System.out.println(s5.lastIndexOf(‘a’,3));
System.out.println(s5.lastIndexOf(‘a’,2));
System.out.println(s5.lastIndexOf(‘a’,7));
}
}
——————————————————————————————
class TestString1{
public static void main(String args[]){
char ch[]={‘a’,’b’,’c’,’d’};
String s1=new String(“ABC”);
String s2=”ABC”;
String s3=new String(“ABC”);
String s4=new String(s3);
String s5=new String();
String s6=new String(ch);
System.out.println(s1+” “+s2+” “+s3+” “+s4+” “+s5+” “+s6);
if(s1==s2){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
if(s1==s3){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
}
}
——————————————————————————————————-
class T1{
public static void main(String arg[]){
String s1=”ABC”;
String s3=”ABC”;
String s2=new String(“ABC”);
String s4=new String(s2);
if(s1==s3){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
if(s1==s2){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
if(s2==s4){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
if(s1.equals(s4)){
System.out.println(“SAME”);
}
else{
System.out.println(“NOT SAME”);
}
}
}
————————————————————————————————–
import java.io.*;
class StringTest1{
public static void main(String args[]){
Console c=System.console();
String st1=c.readLine();
String st2=st1.toUpperCase();
System.out.println(st2);
System.out.println(st1.toLowerCase());
System.out.println(“——————“);
for(int i=0;i<st1.length();i++){ System.out.println(st1.charAt(i)); } for(int i=st1.length()-1;i>=0;i–){
System.out.print(st1.charAt(i));
}
int ctr=0;
for(int i=0;i<st1.length();i++){
char ch=st1.charAt(i);
switch(ch){
case ‘a’:case ‘e’:case ‘i’:case ‘o’:case ‘u’:
case ‘A’:case ‘E’:case ‘I’:case ‘O’:case ‘U’:
System.out.print(“\n”+ch);
ctr++;
}
}
System.out.println(“\n”+ctr);
}
}
————————————————————————————————-
import java.io.*;
class StringTest2{
public static void main(String args[]){
Console c=System.console();
String st1=c.readLine();
System.out.println(st1.substring(3));//from 3rd index to length
System.out.println(st1.substring(3,5));// from 3rd index to 5-1index
}
}
—————————————————————————————————-
import java.io.*;
class StringTest3{
public static void main(String args[]){
Console c=System.console();
String st1=c.readLine(“Enter File Name”);
int i=st1.lastIndexOf(‘.’);
String s=st1.substring(i+1);
System.out.println(“File Type is ” + s);
}
}