Java Strings Interview Questions

    Question 1JAVA - String Immutability

    Why are Strings immutable in Java?

    Question 2JAVA - String Object Creation

    Which of the following creates a new String object in the heap?

    Question 3JAVA - String Concatenation

    What will this code print?

    String s1 = "Hello"; String s2 = "World"; String s3 = s1 + s2; System.out.println(s3);

    Question 4JAVA - String equals() vs ==

    What will be the output?

    String s1 = "Java"; String s2 = new String("Java"); System.out.println(s1 == s2); System.out.println(s1.equals(s2));

    Question 5JAVA - String Length

    What will be printed?

    String str = "Java Programming"; System.out.println(str.length());

    Question 6JAVA - Substring Method

    What will this code print?

    String str = "Interview"; System.out.println(str.substring(0, 5));

    Question 7JAVA - StringBuilder vs StringBuffer

    Which statement is correct?

    Question 8JAVA - String Reverse Example

    What will this code print?

    StringBuilder sb = new StringBuilder("Java"); System.out.println(sb.reverse());

    Question 9JAVA - String Interning

    What does the intern() method of String do?

    Question 10JAVA - String isEmpty() vs isBlank()

    Which is true about isEmpty() vs isBlank()?