· It is final.
· String objects are immutable.
Not methods of this class –append, delete, insert. Hence a code fragment like this causes compiler error ,
String s = “A”;
s.trim();s.append();//causes compiler error since append is not String method
· “valueOf” is static method of String class.
· String has many constructors ,some of the important ones take input parameters
Ø string
Ø stringBuffer
Ø byte array
Ø char array
Ø Doesn’t take in any argument.
→ String constructor doesn’t take in parameter such as char, byte, int, short,
int array ,any array other than char array and byte array etc .
· String class has a method called length() where as array has attribute called ‘length’
hence, String s = “abcd”;
int a = s.length;//causes error
similarlay
int [] a = {1,2,3,4,5};
int b = a.length();//causes error
· String s1 = new String(“abcd”);
String s2 = s1.toString();
here toString method returns the reference to the existing object hence
“s1==s2” will be true.
Note: Even substring(),trim(),concat(),return the same string if they don’t modify the given string.
· String s1 = “santosh”;
String s2 = “santosh”;
then “s1==s2” is true ,since while creating a string object the compiler looks for the same String in the pool and if it finds one then it returns the reference to the existing string.
Note: given ,
String s ,s1 ,s2,s3;
s=s1=s2=s3=null;
{….compelx code….}
s=s1+s2;
s3 = s1+s2;
then “s == s3“ will return false.