srringtext
class StringTest
{
public static void main(String[] args)
{
String str;
str=new String();
System.out.println("str is:"+str);
String str1=new String("abc");
String str2=new String("abc");
String str3=new String(str1);
char ch[]={'h','e','l','l','o'};
String str4=new String(ch);
String str5=new String("ABC");
System.out.println("str1 is:"+str1);
System.out.println("str2 is:"+str2);
System.out.println("str3 is:"+str3);
System.out.println("str4 is:"+str4);
//methods.
System.out.println("charAt(2) in hello is:"+str4.charAt(2));
System.out.println("str1.compareTo(str4)"+str1.compareTo(str4));
System.out.println("str1.compareToIgnoreCase(str5)"+str1.compareToIgnoreCase(str5));
String concat=str4.concat("Uclid");
System.out.println("concat"+concat);
System.out.println("str4.length():"+str4.length());
System.out.println("str1.equals(str2):"+str1.equals(str2));
char []temp=str1.toCharArray();
for(char c:temp){
System.out.print(c);
}
System.out.println();
String lstr="abc";
String lstr1="abc";
System.out.println(str1==str2); //gives you false;
System.out.println(lstr== lstr1); //gives you true;
}
}
class StringTest
{
public static void main(String[] args)
{
String str;
str=new String();
System.out.println("str is:"+str);
String str1=new String("abc");
String str2=new String("abc");
String str3=new String(str1);
char ch[]={'h','e','l','l','o'};
String str4=new String(ch);
String str5=new String("ABC");
System.out.println("str1 is:"+str1);
System.out.println("str2 is:"+str2);
System.out.println("str3 is:"+str3);
System.out.println("str4 is:"+str4);
//methods.
System.out.println("charAt(2) in hello is:"+str4.charAt(2));
System.out.println("str1.compareTo(str4)"+str1.compareTo(str4));
System.out.println("str1.compareToIgnoreCase(str5)"+str1.compareToIgnoreCase(str5));
String concat=str4.concat("Uclid");
System.out.println("concat"+concat);
System.out.println("str4.length():"+str4.length());
System.out.println("str1.equals(str2):"+str1.equals(str2));
char []temp=str1.toCharArray();
for(char c:temp){
System.out.print(c);
}
System.out.println();
String lstr="abc";
String lstr1="abc";
System.out.println(str1==str2); //gives you false;
System.out.println(lstr== lstr1); //gives you true;
}
}