60+ Java Strings Quiz Questions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

60+ Java Strings

Quiz Questions

pramodbablad October 20,


2021 | 0

In this post, there are some 60+


Java strings quiz questions and an‐
swers. I hope it will be helpful for
you to become familiar with Java
strings.

Subscribe To Our Latest


Updates

Join 12,158 other subscribers

1) What is wrong with the below


code? Why it is showing compile
time error?
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

Java 8 Lambda Expressions

Java 8 Functional Interfaces


2) What will be the output of
the following program? Java 8 Method References

1 public class JavaStringsQuiz Java 8 Interface Changes


2 {
3 Java 8 Streams
public static void main(String[] args)
4 {
5 String name = "JavaConceptOfTheDay"
Java 8 Collectors
6
7 System.out.println(name);
Interface Vs Abstract Class After Java
8 }
9 } 8

Collections Vs Streams

Solving Real Time Queries Using Java


3) What will be the output of
8 - Employee Management System
the following code?

1 public class JavaStringsQuiz


2 { Java Interview Questions
3 public static void main(String[] args)
4 { Exception Handling Interview
5 String s = "1".repeat(
Questions
6
7 System.out.println(s);
8 } Strings Interview Questions
9 }
Array Interview Questions

25 Fresher's Basic Java Interview


Questions
4) What will be the output of
the following program? 15 Simple But Confusing Java
Interview Questions
1 public class JavaStringsQuiz
2 {
3 Inheritance
public static void main(String[] args)Interview Questions
4 {
5 System.out.println( Tricky Java Interview Questions
6 }
7 }
Recent Posts :

Java 9 Underscore Changes


5) To which of the following
classes, you can create objects
50+ Java Threads Interview Questions
without using new operator?
And Answers

1. String
60+ Java Strings Quiz Questions
2. StringBuffer
3. StringBuilder Java 9 @SafeVarargs Annotation
Changes

Java 9 Diamond Operator

2 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

6) What will be the output of Improvements


the below program?
Java 9 Try With Resources
1 public class JavaStringsQuiz Improvements
2 {
3 public static void main(String[] args)
4 {
5 String string =
6
7 Popular Posts :
System.out.println(string.substring
8 }
9 }
30+ Java Exception Handling
Interview Questions And Answers

7) In my application, I want mu‐ Solving Real Time Queries Using Java


table and thread safe string ob‐ 8 Features -Employee Management
jects. Which class do you refer System
me to use? String or
StringBuffer or StringBuilder? 110+ Popular Java Interview Programs
With Solutions

Java 8 Stream Intermediate And


8) What will be the output of Terminal Operations
the following program?
Quiz On Increment And Decrement
1 public class JavaStringsQuiz Operators : i++, ++i, i- -, - -i
2 {
3 public static void main(String[] args)
4 { 40 Java Practice Questions On Method
5 System.out.println(
6 } Overloading And Overriding
7 }

9) What will be the outcome of


the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = " Java\tConcept\tOf\t
6
7 System.out.println(str);
8 }
9 }

10) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {

3 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

3 public static void main(String[] args)


4 {
5 if("string".toUpperCase() ==
6 {
7 System.out.println(
8 }
9 else
10 {
11 System.out.println(
12 }
13 }
14 }

11) String, StringBuffer and


StringBuilder – all these three
classes are final classes. True or
False?

12) What will be the output of


the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java"
6
7 String str2 = "Java"
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str
12
13 System.out.println(str1.hashCode()
14 }
15 }

13) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java"
6
7 String str2 = new
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str
12
13 System.out.println(str1.hashCode()
14 }

4 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

15 }

14) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = new
6
7 String str2 = new
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str
12
13 System.out.println(str1.hashCode()
14 }
15 }

15) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java"
6
7 String str2 = str1.intern();
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str
12
13 System.out.println(str1.hashCode()
14 }
15 }

16) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java"
6
7 String str2 = str1.intern();
8
9 String str3 = new
10
11 System.out.println(str1 == str2);
12
13 System.out.println(str2 == str3);

5 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

14
15 System.out.println(str3 == str1);
16 }
17 }

17) What will be the output of


the following code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "1"
6
7 String str2 = "22"
8
9 String str3 = "333"
10
11 System.out.println(str1.concat(str
12 }
13 }

18) hashCode() and equals()


methods are overridden in –

1. java.lang.String
2. java.lang.StringBuffer
3. java.lang.StringBuilder

19) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = "ONE"
6
7 s1.concat("TWO"
8
9 s1.concat("THREE"
10
11 System.out.println(s1);
12 }
13 }

20) What will be the output of


the below program?

6 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = "1";
6
7 System.out.println(s1.concat(
8 }
9 }

21) Tinku is developing an appli‐


cation in which string concate‐
nation is very frequent. Which
string class do you refer him to
use? And also he doesn’t need
code to be thread safe.

22) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

23) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

24) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

7 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

25) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

26) What will be the outcome of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

27) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = new
6
7 String s2 = new
8
9 System.out.println(s1 == s2);
10
11 System.out.println(s1.equals(s2));
12
13 System.out.println(s1 == s2.intern
14
15 System.out.println(s1.intern() ==
16
17 System.out.println(s1.intern() ==
18 }
19 }

28) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)

8 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

4 {
5 System.out.print(
6 System.out.print(
7 System.out.print(
8 System.out.print(
9 System.out.print(
10 System.out.print(
11 }
12 }

29) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 }
7 }

30) join() is an instance method


in java.lang.String class. True or
False?

31) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String[] strings = {
6
7 String languages = String.join(
8
9 System.out.println(languages);
10 }
11 }

32) What will be the output of


the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(
6 System.out.println(
7 }
8 }

9 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

33) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String string =
6
7 StringBuffer sbuffer =
8
9 StringBuilder sBuilder =
10
11 System.out.println(string.equals(s
12
13 System.out.println(string.equals(s
14
15 System.out.println(sbuffer.equals(
16 }
17 }

34) Does java.lang.String class


has static methods? If yes, what
are those?

35) chars() method is intro‐


duced from Java 9 in
java.lang.String class. True or
False?

36) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 "ABC123abc".chars().forEach(System.
6 }
7 }

37) What will be the output of


the below program?

10 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = "null"
6
7 System.out.println(s1);
8 }
9 }

38) Does the following code


compiles successfully? If yes,
what will be the output?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = 1+null
6
7 System.out.println(s1);
8 }
9 }

39) Can we use strings in switch


case?

40) What will be the outcome of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = "Java Concept Of The D
6
7 System.out.println(str.indexOf(
8 }
9 }

41) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = "Java Concept Of The D
6
7 System.out.println(str.indexOf(
8 }

11 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

9 }

42) What will be the output of


the following code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = "JavaConceptOfTheDay"
6
7 System.out.println(str.charAt(str.l
8 }
9 }

43) What is the default capacity


of StringBuffer?

44) What will be the output of


the below code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = "Java Concept Of The D
6
7 System.out.println(str.replace(
8 }
9 }

45) java.lang.String class has


append() method. Right or
Wrong?

46) Does the following code


runs without errors? If yes,
what will be the output?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuilder sb =
6
7 sb.append("ABC"

12 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

8
9 System.out.println(sb);
10 }
11 }

47) What will be the outcome of


the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = null
6
7 System.out.println(str.isBlank());
8 }
9 }

48) What will be the output of


the following code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = " "
6
7 System.out.println(str.isBlank());
8
9 System.out.println(str.isEmpty());
10 }
11 }

49) Does the following code ex‐


ecutes successfully? If yes, what
will be the output?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb =
6
7 sb.append(1.1).append(
8
9 System.out.println(sb);
10 }
11 }

50) What will be the output of


the following program?

13 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuilder sb =
6
7 System.out.println(sb.delete(
8 }
9 }

51) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "123321123"
6
7 System.out.println(str1.replaceFirs
8 }
9 }

52) Which of these classes have


delete() and reverse() method –
java.lang.String,
java.lang.StringBuffer and
java.lang.StringBuilder?

53) What will be the output of


the below code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb =
6
7 System.out.println(sb.insert(
8 }
9 }

54) java.lang.String class imple‐


ments which of the following in‐
terfaces?

1. Serializable
2. CharSequence

14 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

3. Comparable
4. All of the above

55) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java J2EE Spring Hi
6
7 String str2 = "Python Java Scala C
8
9 System.out.println(str1.contains(
10 }
11 }

56) Can you predict the output


of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "OnE tWo ThReE fOuR"
6
7 String str2 = "oNeTwOtHrEeFoUr"
8
9 System.out.println(str1.trim().equ
10 }
11 }

57) Appendable interface is im‐


plemented by which of the fol‐
lowing classes?

1. java.lang.String
2. java.lang.StringBuffer
3. java.lang.StringBuilder
4. java.io.StringWriter
5. 2, 3 & 4

58) Guess the output of the fol‐


lowing program?

15 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb =
6
7 System.out.println(sb.reverse().ind
8 }
9 }

59) StringBuffer and


StringBuilder classes have in‐
tern() method. True or False?

60) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 "Java\nConcept\nOf\nThe\nDay"
6 }
7 }

61) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String[] strings =
6
7 for (String string : strings)
8 {
9 System.out.println(string);
10 }
11 }
12 }

62) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(String.valueOf(
6 }
7 }

16 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

63) Guess the output of the fol‐


lowing program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(String.join(
6 }
7 }

64) What will be the output of


the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb1 =
6
7 StringBuffer sb2 = sb1.append(
8
9 System.out.println(sb1 == sb2);
10 }
11 }

Also Read :

Classes & Objects Quiz


Java Inheritance Quiz
Polymorphism Quiz
Abstract Classes Quiz
Java Interfaces Quiz
Java Modifiers Quiz
Nested Classes Quiz
Java Enums Quiz
Java Arrays Quiz
Java Strings Oracle Docs

17 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

Categories Java Practice Coding


Questions, Strings
Tags Quiz

Java 9 50+ Java


@SafeVarar Threads
gs Interview
Annotation Questions
Changes And
Answers

Leave a Reply

Your email address will not be pub‐


lished. Required fields are marked *
Comment

18 of 19 22-11-2021, 12:17
60+ Java Strings Quiz Questions https://javaconceptoftheday.com/java-strings-quiz-questions-and-answers/

Name * Email * Website

Notify me of follow-up comments


by email.
Notify me of new posts by email.

Post Comment

Java Concept Of The Day © 2021 | About Us | Privacy Policy | Contact Us

19 of 19 22-11-2021, 12:17

You might also like