Skills101
← All practice quizzes

Quiz: Java Strings

5 questionsNo time limitPass: 60%+10 XP on first pass

Why == fails for strings, how the string pool works, the most-used String methods, StringBuilder for fast building, and string interview programs.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    public class Main {
        public static void main(String[] args) {
            String a = "hi";
            String b = new String("hi");
            System.out.println(a == b);
        }
    }
    
  2. Question 2

    What does this print?

    public class Main {
        public static void main(String[] args) {
            System.out.println("Placement".substring(2, 5));
        }
    }
    
  3. Question 3

    Which is the fastest choice to build a long string in a single-threaded loop?

  4. Question 4

    Why are Java Strings immutable? (pick the best reason)

  5. Question 5

    What does this print?

    public class Main {
        public static void main(String[] args) {
            String s = "abc";
            s.concat("def");
            System.out.println(s);
        }
    }