String Handling

This Test will cover String Handling from basic to advanced level. All the functions of String Class and StringBuffer and StringBuilder too.

Q. What is an immutable object?
Q. Which of the following is not a valid way to create String object?

Q. String objects are stored in a special memory area known as?
Q. What will be the result of given code?
String str = "Java";
String str1 = new String("Java");
  
System.out.println(str.equals(str1));
System.out.println(str == str1);
System.out.println( str.compareTo(str1) );
Q. What will be the result of given code?
String str = "StudyTonight";
str.concat(".com");
str = str.toUpperCase();
str.replace("TONIGHT","today");
System.out.println(str);
Q. How many new objects are created in given code?
String str = new String("Hello");
Q. Which method is used to convert a primitive type into String?

Q. Which method is used to remove leading and trailing whitespace(s)?
Q. What will be the output of following code?
String str = "Java was developed by James Ghosling";
System.out.println(str.substring(19));
Q. What will happen if you try to run the following code?
  String str = "Java Learners";
  StringBuffer sb = new StringBuffer();
  for(int i=0; i < str.length(); i++)
  sb.append(str.charAt(i));
  System.out.println(sb);
Q. Which class is used to create mutable and non-synchronised string?

SUBMIT TEST