Arrays & Strings

11.What is the output of the following code?
public class Main { public static void main(String[] args) { String str = " Java "; System.out.println(str.trim()); } }
  • A. Java
  • B. Java
  • C. Java
  • D. Java

Java

Java

12. What does the StringBuilder class provide in Java?
  • A. Immutable string handling
  • B. Fast and efficient string manipulation
  • C. Better security than String
  • D. Only works with arrays

Fast and efficient string manipulation

Fast and efficient string manipulation

13.What is the difference between String and StringBuilder?
  • A. String is mutable, StringBuilder is immutable
  • B. String is immutable, StringBuilder is mutable
  • C. Both are immutable
  • D. Both are mutable

String is immutable, StringBuilder is mutable

String is immutable, StringBuilder is mutable

14.What will be the output of the following code?
public class Main { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Java"); sb.append(" Programming"); System.out.println(sb); } }
  • A. JavaProgramming
  • B. Java Programming
  • C. Compilation error
  • D. Java + Programming

Java Programming

Java Programming

15.What happens when you concatenate strings using + operator in Java?
  • A. A new string is created each time
  • B. The original string is modified
  • C. Performance improves
  • D. Compilation error

A new string is created each time

A new string is created each time