R&D with String and StringBuffer.
**************************************************************
package SCJP;
public class StringExample1
{
public static void main(String[] args)
{
boolean s1 = "Arun" == "Arun";
boolean s2 = new String("Arun") == "Arun";
boolean s3 = new String("Arun") == new String("Arun");
System.out.println("S1 is "+s1);
System.out.println("S2 is "+s2);
System.out.println("S3 is "+s3);
System.out.println("(s2&&s3||s1) is "+(s2&&s3||s1));
}
}
Output =>
S1 is true
S2 is false
S3 is false
(s2&&s3||s1) is true
*****************************************************************
package SCJP;
public class StringExample2
{
public static void main(String arun[])
{
boolean s1 = "Arun" == "Arun";
boolean s2 = new String("Arun").equals(new String("Arun"));
boolean s3 = "Arun".toString() == "Arun";
System.out.println("S1 is "+s1);
System.out.println("S2 is "+s2);
System.out.println("S3 is "+s3);
System.out.println("(s1&&s2&&s3) is "+(s1&&s2&&s3));
}
}
Output =>
S1 is true
S2 is true
S3 is true
(s1&&s2&&s3) is true
******************************************************************
package SCJP;
public class StringExample3
{
public static void main(String[] args)
{
StringBuffer sb = "";//compile time error.
}
}
*******************************************************************
package SCJP;
public class StringExample4
{
public static void main(String[] args)
{
String s = null;
System.out.println(null+s);
}
}
Output =>
nullnull
*********************************************************************
**************************************************************
package SCJP;
public class StringExample1
{
public static void main(String[] args)
{
boolean s1 = "Arun" == "Arun";
boolean s2 = new String("Arun") == "Arun";
boolean s3 = new String("Arun") == new String("Arun");
System.out.println("S1 is "+s1);
System.out.println("S2 is "+s2);
System.out.println("S3 is "+s3);
System.out.println("(s2&&s3||s1) is "+(s2&&s3||s1));
}
}
Output =>
S1 is true
S2 is false
S3 is false
(s2&&s3||s1) is true
*****************************************************************
package SCJP;
public class StringExample2
{
public static void main(String arun[])
{
boolean s1 = "Arun" == "Arun";
boolean s2 = new String("Arun").equals(new String("Arun"));
boolean s3 = "Arun".toString() == "Arun";
System.out.println("S1 is "+s1);
System.out.println("S2 is "+s2);
System.out.println("S3 is "+s3);
System.out.println("(s1&&s2&&s3) is "+(s1&&s2&&s3));
}
}
Output =>
S1 is true
S2 is true
S3 is true
(s1&&s2&&s3) is true
******************************************************************
package SCJP;
public class StringExample3
{
public static void main(String[] args)
{
StringBuffer sb = "";//compile time error.
}
}
*******************************************************************
package SCJP;
public class StringExample4
{
public static void main(String[] args)
{
String s = null;
System.out.println(null+s);
}
}
Output =>
nullnull
*********************************************************************
No comments:
Post a Comment