code#SBTest.java
----------------
public class SBTest
{
static StringBuffer s;
public static void main(String[] args)
{
StringBuffer result=new StringBuffer();
result.append(s);
System.out.println(result);
}
}
code#STest.java
public class STest
{
static String s;
public static void main(String[] args)
{
String result=new String();
result.concat(s);
System.out.println(result);
}
}
Here the Ist one comiles fine and output null. But 2nd code gives NullPointerException. Pl explain the reason why it is ok for StringBuffer but not ok for String.
----------------
public class SBTest
{
static StringBuffer s;
public static void main(String[] args)
{
StringBuffer result=new StringBuffer();
result.append(s);
System.out.println(result);
}
}
code#STest.java
public class STest
{
static String s;
public static void main(String[] args)
{
String result=new String();
result.concat(s);
System.out.println(result);
}
}
Here the Ist one comiles fine and output null. But 2nd code gives NullPointerException. Pl explain the reason why it is ok for StringBuffer but not ok for String.