Strings

1. Why String is immutable?
2. What is the difference == and equals() method If we are comparing two strings?
3. Output of below code
   String str1="Java String";
   String str2="Java String";
   String str3=new String("Java String");
 
   System.out.println(str1==str2?"true":"false");
   System.out.println(str1==str3?"true":"false");
   System.out.println(str1.equals(str3)?"true":"false");
4. How many objects will be created in below statements?
   String str1="Java";
   String str2="String";
   String str3="Java String";
   String str4=str1+str2;
5. Find the length of the string with using length() method of string.
6. Have you used substring() method of String? Do you find any issue while using it?
7. Why character array is preferred over String to store passwords?
8. How String pool is garbage collected?
9. Can we make a subclass of String class?
10.String is immutable so why below is allowed?
   String str="Java String";
   str=str+" Changed";

No comments:

Post a Comment