60+ Java String Snippets CCEE MCQ
60+ Java String Snippets CCEE MCQ
Sr.No
Project Name YouTube Link
11 Tour and Travel System Project version 3.0 https://youtu.be/Dm7nOdpasWg?si=P_Lh2gcOFhlyudug
12 Gym Management system Project https://youtu.be/J8_7Zrkg7ag?si=LcxV51ynfUB7OptX
13 Online Driving License system Project https://youtu.be/3yRzsMs8TLE?si=JRI_z4FDx4Gmt7fn
14 Online Flight Booking system Project https://youtu.be/m755rOwdk8U?si=HURvAY2VnizIyJlh
15 Employee management system project https://youtu.be/lD1iE3W_GRw?si=Y_jv1xV_BljhrD0H
16 Online student school or college portal https://youtu.be/4A25aEKfei0?si=RoVgZtxMk9TPdQvD
17 Online movie booking system project https://youtu.be/Lfjv_U74SC4?si=fiDvrhhrjb4KSlSm
18 Online Pizza Delivery system project https://youtu.be/Tp3izreZ458?si=8eWAOzA8SVdNwlyM
19 Online Crime Reporting system Project https://youtu.be/0UlzReSk9tQ?si=6vN0e70TVY1GOwPO
20 Online Children Adoption Project https://youtu.be/3T5HC2HKyT4?si=bntP78niYH802I7N
pg. 4 contact us on 8007592194 / 9284926333 www.codewitharrays.in
1) What is wrong with the below code? Why it is showing compile time error?
View Answer
4
9 }
9
21
View Answer
59
ConceptOfTheDay 07
80
5 String s = "1".repeat(5);
6
ar
7 System.out.println(s);
8 }
ith
9 }
w
de
View Answer
co
11111
View Answer
5) To which of the following classes, you can create objects without using new operator?
. String
. StringBuffer
. StringBuilder
View Answer
1. String
View Answer
r0n
9 4
21
7) In my application, I want mutable and thread safe string objects. Which class do you refer me to use? String or StringBuffer
or StringBuilder?
59
View Answer
07
StringBuffer as it provides mutable and thread safe string objects.
80
2 {
3 public static void main(String[] args)
ra
4 {
ar
7 }
w
View Answer
de
co
false
View Answer
View Answer
false
11) String, StringBuffer and StringBuilder – all these three classes are final classes. True or False?
View Answer
9 4
True
21
59
12) What will be the output of the below program?
07
1 public class JavaStringsQuiz
2 {
80
6
7 String str2 = "Java";
ys
8
9 System.out.println(str1 == str2);
ra
10
ar
11 System.out.println(str1.equals(str2));
12
ith
13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
w
15 }
de
View Answer
co
true
true
true
false
true
true
49
21
1 public class JavaStringsQuiz
2 {
59
3 public static void main(String[] args)
4 { 07
5 String str1 = new String("Java");
6
7 String str2 = new String("Java");
80
8
9 System.out.println(str1 == str2);
.in
10
11 System.out.println(str1.equals(str2));
12
ys
13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
ra
15 }
ar
ith
View Answer
w
false
de
true
true
co
View Answer
true
true
true
9 4
21
View Answer
59
true
false
07
false
80
2 {
3 public static void main(String[] args)
ra
4 {
5 String str1 = "1";
ar
6
7 String str2 = "22";
ith
8
9 String str3 = "333";
w
10
de
11 System.out.println(str1.concat(str2).concat(str3).repeat(3));
12 }
co
13 }
View Answer
122333122333122333
1) java.lang.String
View Answer
ONE
4
7 System.out.println(s1.concat("2").concat("3"));
9
8 }
21
9 }
59
View Answer 07
123
80
.in
21) Tinku is developing an application in which string concatenation is very frequent. Which string class do you refer him to
use? And also he doesn’t need code to be thread safe.
ys
View Answer
ra
In such scenarios where string concatenation is very frequent, StringBuffer and StringBuilder classes give better performance than
ar
String class. As StringBuffer is thread safe and StringBuilder is not, StringBuilder will be optimal choice here.
ith
w
View Answer
Java100020003000
6000Java
View Answer
11.0Java3.37.7
9 4
1 public class JavaStringsQuiz
21
2 {
3 public static void main(String[] args)
59
4 {
5 System.out.println("ONE"+2+3+4+"FIVE");
6 }
07
7 }
80
View Answer
.in
ONE234FIVE
ys
ra
2 {
3 public static void main(String[] args)
w
4 {
de
5 System.out.println("JAVAJ2EE".substring(2, 5).substring(1).charAt(2));
6 }
co
7 }
View Answer
View Answer
false
true
false
true
false
4
8 System.out.print("3".indent(3));
9
9 System.out.print("4".indent(4));
21
10 System.out.print("5".indent(5));
11 }
59
12 }
07
View Answer
80
0
1
.in
2
3
ys
4
5
ra
ar
2 {
de
View Answer
View Answer
Java_Python_JavaScript_HTML_CSS
94
21
View Answer
59
-1
1
07
80
11 System.out.println(string.equals(sbuffer));
de
12
13 System.out.println(string.equals(sBuilder));
14
co
15 System.out.println(sbuffer.equals(sBuilder));
16 }
17 }
View Answer
false
false
false
34) Does java.lang.String class has static methods? If yes, what are those?
View Answer
35) chars() method is introduced from Java 9 in java.lang.String class. True or False?
View Answer
True
View Answer
9 4
65
21
66
67
49
59
50
51
07
97
98
80
99
.in
2 {
3 public static void main(String[] args)
ar
4 {
5 String s1 = "null"+null+1;
ith
6
7 System.out.println(s1);
w
8 }
de
9 }
co
View Answer
nullnull1
38) Does the following code compiles successfully? If yes, what will be the output?
View Answer
No. Above code shows compile time error. You can use ‘+’ for string and null but not for int and null.
39) Can we use strings in switch case?
View Answer
View Answer
21
9 4
21
41) What will be the output of the following program?
59
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
07
4 {
5 String str = "Java Concept Of The Day";
80
6
7 System.out.println(str.indexOf('a', 5));
8 }
.in
9 }
ys
View Answer
ra
ar
21
ith
w
2 {
3 public static void main(String[] args)
4 {
5 String str = "JavaConceptOfTheDay";
6
7 System.out.println(str.charAt(str.length()));
8 }
9 }
View Answer
16
View Answer
-1
46) Does the following code runs without errors? If yes, what will be the output?
4
2 {
9
3 public static void main(String[] args)
21
4 {
5 StringBuilder sb = new StringBuilder(-32);
59
6
7 sb.append("ABC"); 07
8
9 System.out.println(sb);
10 }
80
11 }
.in
View Answer
ys
Above code throws run time error. Initial capacity of StringBuilder can’t be negative.
ra
ar
2 {
de
View Answer
Exception in thread “main” java.lang.NullPointerException: Cannot invoke “String.isBlank()” because “str” is null
View Answer
true
false
49) Does the following code executes successfully? If yes, what will be the output?
View Answer
9 4
21
Yes, above code executes successfully. Output will be,
012341.1A22falsenull
59
50) What will be the output of the following program?
07
80
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
.in
4 {
5 StringBuilder sb = new StringBuilder("0123456789");
ys
6
7 System.out.println(sb.delete(3, 6).deleteCharAt(4).deleteCharAt(5));
ra
8 }
9 }
ar
ith
View Answer
w
de
01268
co
View Answer
321
52) Which of these classes have delete() and reverse() method – java.lang.String, java.lang.StringBuffer and
java.lang.StringBuilder?
View Answer
java.lang.StringBuffer and java.lang.StringBuilder have delete() and reverse() methods.
View Answer
111fa3.One3lse11
4
. CharSequence
9
. Comparable
21
. All of the above
59
View Answer
07
4. All of the above
80
2 {
3 public static void main(String[] args)
ra
4 {
5 String str1 = "Java J2EE Spring Hibenate SQL";
ar
6
7 String str2 = "Python Java Scala C C++";
ith
8
9 System.out.println(str1.contains("HTML") == str2.contains("HTML"));
w
10 }
de
11 }
co
View Answer
true
View Answer
false
5) 2, 3 & 4
4
7 System.out.println(sb.reverse().indexOf("Two"));
9
8 }
21
9 }
59
View Answer 07
-1
80
.in
59) StringBuffer and StringBuilder classes have intern() method. True or False?
View Answer
ys
ra
False
ar
ith
2 {
3 public static void main(String[] args)
co
4 {
5 "Java\nConcept\nOf\nThe\nDay".lines().forEach(System.out::println);
6 }
7 }
View Answer
Java
Concept
Of
The
Day
View Answer
Java
Concept
Of_The_Day
4
View Answer
9
21
101.1true
59
63) Guess the output of the following program?
07
80
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
.in
4 {
5 System.out.println(String.join(",", "1", "2", "3").concat(",").repeat(3).lastIndexOf(','));
ys
6 }
7 }
ra
ar
View Answer
ith
17
w
de
View Answer
true
https://www.youtube.com/@codewitharrays
https://www.instagram.com/codewitharrays/
codewitharrays@gmail.com
https://codewitharrays.in/project