Java Strings MCQs with answers
60 questions tagged Java Strings, each with the correct answer and an explanation. Page 1 of 3.
- How many objects are created? String s1 = "abc"; String s2 = new String("abc");
- What is the difference between "abc" and new String("abc")?
- What will happen if you call length() on a null String?
- What is the return type of `charAt()` method?
- What will "hello".compareTo("hello") return?
- What is the use of intern() method?
- How to convert a string to an array of bytes?
- What will this code output? String str = ""; System.out.println(str.isEmpty());
- Which is true about StringBuilder and String?
- What is the default value of a String reference in Java?
- Which method can split a string using a regular expression?
- What is the output? System.out.println("Java".length());
- What will be the result of: "hello".replace('l', 'x')?
- How can you convert an integer to a string in Java?
- Which method is used to check if a string matches a given regular expression?
- How to find the first occurrence of 'e' in the string "hello"?
- What is the result of: "abc".equalsIgnoreCase("ABC")?
- Which of the following is NOT a valid string method?
- What will be the output of: System.out.println("Java".substring(1, 3));
- Which method is used to get a part of the string starting from a specific index?