Java String Interview Questions and Answers - JournalDev
Java String Interview Questions and Answers - JournalDev
Answers
Pankaj - 186 Comments
Home » Interview Questions » Java String Interview Questions and Answers
AD
String is one of the most widely used Java Class.
Here I am listing some important Java String
Interview Questions and Answers.
if (str.charAt(i) != str.charA
return false;
}
return true;
}
String s1 = "abc";
String s2 = "abc";
String s3= new String("abc");
System.out.println("s1 == s2 ? "+(
System.out.println("s1 == s3 ? "+(
System.out.println("s1 equals s3 ?
package com.journaldev.strings;
package com.journaldev.strings;
String s1 = "abc";
StringBuffer s2 = new StringBuffer(s1);
System.out.println(s1.equals(s2));
String s1 = "abc";
String s2 = new String("abc");
s2.intern();
System.out.println(s1 ==s2);
The answer is 3.
First – line 1, “Hello” object in the string pool.
Second – line 1, new String with value “Hello”
in the heap memory.
Third – line 2, new String with value “Hello” in
the heap memory. Here “Hello” string from
string pool is reused.
Further Reading
PREV
NEXT
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 9/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Pankaj
I love Open
Source
technologies Follow Author
and writing
about my
experience
about them
is my
passion.
Comments
Hi Sir,
Thanks for advance.
My question is to you what is the need
of intern() method.As of now my
understanding while creating instance
to String using new operator it will be
in String pool and heap memory as of
your 6 question answer And when we
create instance for string using double
quote automatically store into string
constant pool. Could you please clarify
on the same
Reply
Hi Pankaj,
Good collection on Strings. Appreciate
your e orts. I have only one doubt on
String pool. Your statements regarding
the below question is contradictory.
What are di erent ways to create String
Object?
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 10/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Hii surya
trim() function is method of spring
which eliminate spaces before the
string and spaces a er string
for example:
str1=” sumit”;//here is a space
before String
str1.trim();
System.out.println(str1);// output
will be “sumit” Here is no space
before string
Reply
satya says:
October 15, 2019 at 1:44 am
Hi Dharmendra,
the above example, you
didn’t assigned again to str1 Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 12/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
object.
str1=” sumit”;//here is a
space before String
str1=str1.trim();
System.out.println(str1);//
output will be “sumit” Here is
no space before string
Reply
ShubhamAugust
says:31, 2018 at 10:43 pm
Pankaj says:
September 1, 2018 at 9:41 am
sachin September
says: 21, 2018 at 8:06 am
case : 1
String a1=”hello”;
String a2=”hello”;
String a3=new String(“hello”);
as per pankaj’s comment: 2
objects will be created ( rst
a1 in string pool, then a3 in
heap.)
so according to the above
result,if we consider below Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 14/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
problem then
String s1 = new
String(“Hello”); //1 object
creation in heap due to new
String s2 = new
String(“Hello”); //2nd object
in heap due to new
total 2 object must be
created .
question to pankaj , as per
your above comments, why
“hello” should be in string
constant pool(as it already
allocated via heap segment &
will cause 2 times memory
allocation.
please reply ..
Reply
thanks ,
Reply
2 objects
Reply
1,
When the intern method is Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 15/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
2 objects.
rst is argument in String
constructor “abc” will be created
in string pool – new String(“abc”)
second will be created in the
Heap by the ‘new’ operator
the .intern() method invokes a er
this 2 objects created, then
checks in string pool for “abc” (
which is there) and return a
reference to it
– in this case we have no
reference to the object created in
the heap by the new operator
– second line doesn’t change
number of objects created
Reply
3 objects because
for s1 – (one objects is created in
string constant pool and one is
created in non-constant pool or
heap ) here, 2 obj.
now, for s2 – there is only one
object is created in scp(string
constant pool).
thus, 3 objects are created .
Reply
Hi Pankaj,
I read all the comments and got more
confused. Can you please explain the
pointers below.
In “What are di erent ways to create
String Object?” you answered:
When we use new operator, JVM
creates the String object but don’t
store it into the String Pool. We can use
intern() method to store the String
object into String pool or return the
reference if there is already a String
with equal value present in the pool.
and then in last 6th question “How
many String objects got created in
below code snippet?” you answered.
String s1 = new String(“Hello”);
String s2 = new String(“Hello”);
Answer is 3.
First – line 1, “Hello” object in the string
pool.
Second – line 1, new String with value
“Hello” in the heap memory.
Third – line 2, new String with value
“Hello” in the heap memory. Here
“Hello” string from string pool is
reused.
So will it store the object in String pool
or not. I hope this will clear things to all
Reply
waqas_kamran says:
February 15, 2018 at 11:04 pm
Im totally confused.
in one article you write
“When we use new operator, JVM
creates the String object but don’t
store it into the String Pool. ”
in another
“String str = new String(“Cat”);
In above statement, either 1 or 2 string
will be created. If there is already a
string literal “Cat” in the pool, then only
one string “str” will be created in the
pool. If there is no string literal “Cat” in
the pool, then it will be rst created in
the pool and then in the heap space, so
total 2 string objects will be created.”
So which one is right ?
Reply
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 18/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
absolutely right
Reply
TirupathiNovember
Reddy 9,says:
2017 at 6:40 am
Hi ,
According to your answer
just think if it will create two
objects one in heap and one
in pool then what is the use
of intern() method in String.
Reply
Ajeet March
Kumar says:
5, 2018 at 11:26 am
String s1 = “Rakesh”;
String s2 = “Rakesh”;
//s1 and s2 referencing
to same object in Pool
String s3 =
“Rakesh”.intern(); //s1 ,
s2 and s3 referencing to
same object in Pool
String s4 = new
String(“Rakesh”); //s4
creates in Heap and
referencing to same in
Heap
String s5 = new
String(“Rakesh”).intern();
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 19/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
//again s5 referencing to
Literal in Pool so s1, s2,
s3 and s5 are referncing
to same object in Pool
if ( s1 == s2 ){
System.out.println(“s1
and s2 are same”); // 1.
}
if ( s1 == s3 ){
System.out.println(“s1
and s3 are same” ); // 2.
}
if ( s1 == s4 ){
System.out.println(“s1
and s4 are same” ); // 3.
}
if ( s1 == s5 ){
System.out.println(“s1
and s5 are same” ); // 4.
}
will return:
s1 and s2 are same
s1 and s3 are same
s1 and s5 are same
Reply
bhargav says:
July 16, 2017 at 5:05 am
Tirupathi Reddy
November 9, 2017 says:
at 6:45 am
Hello arun,
I think the rst two methods for
creating string are optimum .
The 3rd method i.e String.valueOf
(arg a) returns the string
representation of the passed
argument for char,boolean,int and
double. whereas 4th method only
concats two string and creates
another object of String classs.
please correct me if i am wrong.
Reply
Hi Pankaji,
thanks for the tutorial, is very good.
I have doubts about last exercise:
How many String objects got created in
below code snippet?
String s1 = new String(“Hello”);
String s2 = new String(“Hello”);
You say that the object created will be
3. I would answered 2, as new operator
creates new object in the heap memory
(not in the string pool) regardless of
wheter there is same string stored in
the string pool.
Why you say 3?
Thanks in advice.
Reply
Pankaj says:
December 31, 2016 at 11:17 am
Hareesh January
says: 4, 2017 at 10:30 am
operator.
String s1 = new
String(“Hello”);
String s2 = new
String(“Hello”);
I am thinking this objects will
store only in Heap. If I am
wrong correct me how
exactly String objects store?.
Reply
Hareesh says:
January 4, 2017 at 7:52 pm
Harshal
Marchsays:
11, 2017 at 11:47 pm
sachinApril
says:12, 2017 at 7:27 am
SzanowneJanuary
says:6, 2017 at 1:14 pm
I am confused, as far as I
leant, string created with new
operator goes into heap
memory, NOT in the String
pool. So why in this case an
object is added in String
pool?
I thought that in this case,
the only way to add one of
this objects in the string pool
is using intern(), so smtg like
this:
String s1 = new
String(“Hello”).intern();
Reply
Dushyant
FebruarySheoran says:
17, 2017 at 7:38 am
(String constant
pool(scp)) in the name
only meaning is there
constant values are
stored in scp.
example String s1=new
String(“hello”);;
hello is constant one
object is created in scp
and new keyword create
another object in heap
area.
if you give String
s1=”arun” ————-
>arun is constant object
created in scp only
String s1=”arun”
String
s2=”arun”______________
________>in this case
only 1 object is created
for s1 and s2.
in scp already same
content exists no object
created
Reply
Hi Pankaj,
can u please look on the following,
String s1=new String(“sun”);
String s=”sun”;
System.out.println(s1.hashCode());
System.out.println(s.hashCode());
System.out.println(s1==s);
O/P:
-1856818256
-1856818256
false.
here 1st i am creating s1 with new
keyword .so as you said , its creates
object in heap memory and in pool,next
i created using literal which will creates
object only in pool. As the s1 and s are
present in the pool so they are having
same hashcode, but when i am
comparing them why its giving
false.?????
Reply
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 25/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
hi pankaj,
can u please explain the following
doubt….
String have two methods for creating
one is literal,another way is new
keyword ,if literal is the way which is
memory e cient ,then why we also
using ‘new’ ,please explain the
scenarios where we can use them and
main di erentiating point to use them.
Reply
Hi,
I have one doubts for below code.
String str = “test”;
str = str+”test2″;
str = str+”test3″;
str = str + ”test4″;
str = str + “test5”;
Now many objects will be created and
how many objects will be available for
garbage collection?
Can you please explain this?
Reply
AtSvm says:
January 15, 2017 at 11:40 am
, “test5” ,
“testtest2test3test4test5”
and str will point to
testtest2test3test4test5 at the
end .
So remaining all 8 literals will
be eligible for Garbage
Collection.
Reply
“testtest2test3” ,
“testtest2test3test4” ,
“testtest2test3test4test5”
and now str which was refering to
“testtest2test3test4” start
referering to
“testtest2test3test4test5”
So if you put S.O.P(str) =
testtest2test3test4test5
and check how many “” object are
there
test
testtest2
testtest2test3
testtest2test3test4
testtest2test3test4test5
=== Fiveeeeeeeeeeeeee
Reply
My program is:::
package interviews;
public class InternMethod {
public static void main(String[] args) {
String str1=”java”;
String str2=str1.intern();
String str3=new String(str1.intern());
System.out.println(“hash1=”+str1.hashC
ode());
System.out.println(“hash2=”+str2.hashC
ode());
System.out.println(“hash3=”+str3.hashC
ode());
System.out.println(“str1==str2==>>”+
(str1==str2));
System.out.println(“str1==str3==>>”+
(str1==str3));
}
}
=================================
===========output===>
hash1=3254818
hash2=3254818
hash3=3254818
str1==str2==>>true
str1==str3==>>false
=================================
Can anyone explain how == returns
false even though s1 and s3 having
same hashcode?
Reply
Pankaj says:
September 30, 2016 at 12:09 am
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 28/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Reply
False
Reply
false
Reply
Hi Pankaj,
In di erent ways to create string you
have said:
“When we use new operator, JVM
creates the String object but DON’T
store it into the String Pool. ”
And in string programming question:
String s1 = new String(“Hello”);
String s2 = new String(“Hello”);
Athough string s1 is creating using new
operator, you are saying Hello will be
saved in String pool.
Isn’t both statements are contradictory.
Kindly let me know if I am missing
something here.
Thanks,
Gaurav
Reply
GAURAV PANT
July 5,says:
2016 at 11:21 pm
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 29/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Pankaj July
says:6, 2016 at 9:15 am
4 objects
First – line 1, “abc” object in the
string pool.
Second – line 1, new String with
value “abc” in the heap memory.
Third – line 2, new String with
value “xyz” in the heap memory.
Fourth – line 2, “xyz” object in the
string pool
Here since the value of string is
di erent for both str1 and str2
hence “abc”,”xyz” string from
string pool is not reused.
Reply
arun says:
February 18, 2017 at 9:47 am
yes it is correct
Reply
chandini says:
March 20, 2017 at 3:52 am
Puneet SrivastavaJune
says:
8, 2016 at 9:35 pm
1. String s1 = new
String(“Hello”);
2. String s2 = new
String(“Hello”);
Answer is 3.
Then how three object
created here.
I am very confused here.
According to you when you
create String through new
Keyword it will create two
object one is on constant
pool and another one is on
heap.please correct me if am
wrong.
Reply
Pankaj June
says:
2, 2016 at 7:16 am
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 32/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Pankaj says:
June 19, 2016 at 1:39 am
Verma
Thanks Pankaj for
the reply it really
help.
Navneet says:
July 1, 2016 at 3:54 am
Mandeep says:
July 24, 2016 at 1:35 am
without calling
intern() method
how can Hello can
be stored in pool.
chandini says:
March 20, 2017 at 4:01 am
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 33/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Hareesh says:
January 4, 2017 at 7:35 pm
Thanks Raju.
Reply
Hii pankaj,
Your articles are super, rst i tq u to ur
thinking like to make it all useful info
into one place.
Reply
Pankaj says:
December 12, 2015 at 11:15 pm
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 34/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
PraveenDecember
Kumar 17, 2015 at 7:42 am
says:
Hi ,
I am a great fan of your
articles. It would be awesome
if you could integrate disqus
in your blog for comments. I
have a little doubt regarding
strings in java. Can you tell
me how many objects are
created in these two lines of
code ?
StringBuilder sb = new
StringBuilder(“abc”);
sb.append(“def”);
Kindly mail me if possible.
Thanks a lot.
Reply
Hareesh says:
January 4, 2017 at 7:44 pm
Hi Praveen,
StringBu er is
immutable.
at this line StringBuilder
sb = new
StringBuilder(“abc”); —
>one object created
sb.append(“def”); —-
>you are trying to
change content. so
existing object goes for
GC and a new object
created with “abcdef”
Reply
Vishnu says:
March 25, 2017 at 7:58 am
Prasad
Hi Hareesh..
You are wrong.
StringBuilder is
Mutable .
If you create
StringBuilder
sb=new
StringBuilder(“abc”
); then only one
object will be
created..and if you
are try to modify
StringBuilder
Object then new
object are not
create.Only modify
on that object..
Because
StringBuilder
capacity is
ByDefault 16.and
It’s Mutable
StringBuilder sb =
new
StringBuilder(“abc”
);
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 35/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
System.out.println(
sb.capacity());// 16
For Example-
StringBuilder sb =
new
StringBuilder(“abc”
);
System.out.println(
sb.capacity());//19
=> 3 abc+16 default
System.out.println(
sb.length());//3
sb.append(“def”);
System.out.println(
sb.capacity());//19
System.out.println(
sb.length());//6
If Default capacity
is full then JVM will
create a new
Object ..
sb.append(“I self
Vishnu”);
System.out.println(
sb.capacity());//19
System.out.println(
sb.length());//19
Hear Default
capacity is full
again if you try to
modify then JVM
will create new
Object
and copy all data
of previous Object
a er then destroy
the previous
Object
like :formula of
New Object
Capacity:
New Capacity=
(Initial
Capacity*2)+2
=(19*2)+2
=38+2=40
Ex:
sb.append(“Prasad
”);
System.out.println(
sb.capacity());//40
System.out.println(
sb.length());//25
If you De ne our
own capacity then
Create the
StringBuilder
Object to Following
way..
StringBilder(int
Initial Capacity);
Ex:=>
Previous Next
StringBuilder
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 36/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
sb1=new
StringBuilder(100);
System.out.println(
sb1.capacity());
//100
System.out.println(
sb1.length()); //0
Pankaj says:
November 11, 2015 at 10:28 pm
Hey Pankaj…..
Where is comparison operator in
Question 1 for which U R saying that
don’t confuse with that?
Reply
Dear sir,
I have one basic question.
Why java supports both features of
string string creation.
String str=”abc”; Previous Next
String strObj=new String(“abc”);
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 37/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Chetan says:
September 23, 2015 at 12:59 pm
ashishNovember
says: 20, 2015 at 10:23 pm
Ashutosh says:
February 17, 2016 at 1:09 pm
Hi Pankaj,
Very useful work………
keep it up…
Reply
I need program:
write a java program to give the spaces
b/w words
Ex:
i/o : ramisagoodboy
o/p : ram is a good boy
Reply
siddharth says:
September 9, 2015 at 5:02 am
hi..
How to print program source code as
output in java language..?
Reply
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 39/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Hi pankaj,
I have a question in string permutation?
for example: Input: sarita
key :ri
the out put should be :sarita, sarIta,
saRita, saRIta
Reply
Hi,
I need a solution for this
Consider String str1 = “hari”;
String str2 = “malar”;
now nd the same characters in both
the string and delete the repeated
characters
So, the output must be
str1 = hi
str2 = mla
Reply
Hi Pankaj,
I have one doubt. I want to know if we
execute the below statements then
how many objects and references will
be created on each line 1, 2 and 3.
1.) String s1 = “abc”;
2.) String s2 = “abc”;
3.) String s3= new String(“abc”);
Thanks,
Ishan
Reply
Pankaj says:
September 20, 2014 at 10:36 am
vallabhiSeptember
says: 25, 2014 at 2:20 am
Hi Pankaj
Thanks for these wonderful
questions
I have a doubt that if we can
create objects through String
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 40/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Pankaj says:
September 25, 2014 at 2:55 am
Since String is an
Object and we can use
new operator to
instantiate it. It’s not
possible to remove this
option.
Reply
vallabhi
September says:
25, 2014 at 5:42 am
Ruchi Gupta
September says:
29, 2014 at 5:12 am
chandini says:
March 20, 2017 at 4:24 am
I hope those
strings will be
there as long as
their scope
Anoop December
says: 17, 2014 at 3:26 am
Hello Ishan,
String x = “abc”;
// It creates 1 String object and 1
reference variable.
//”abc” will go to pool memory
and x will refer to it.
String y = new String(“xyz”);
//It creates 2 objects and one
reference variable.
//In this case, because we used
the new keyword, java will create
a new String object in the normal
(non-pool) memory, one object in
the pool memory(for storing
“xyz”), and y will refer to it.
1.) String s1 = “abc”; -> 1 object
and 1 refercene
2.) String s2 = “abc”; -> 0 object
and 1 reference
3.) String s3= new String(“abc”); ->
2 objects and 1 reference.
So the correct answer to your
question would be 3 objects and 3
reference.
Regards
Dhruba
Reply
Pankaj says:
September 11, 2014 at 11:09 pm
RajeshSeptember
says: 24, 2014 at 11:40 am
Pankaj says:
September 25, 2014 at 1:19 am
Anshul says:
November 14, 2014 at 9:27 am Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 43/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
lol….pankaj is saying
String class is declared
nal in JDK source code
dumbo…
nal class String {} in
JDK
Reply
Hareesh says:
January 4, 2017 at 9:42 pm
Hi ,
in answer of ‘What are di erent ways to
create String Object?’ you have said
when we use new operator with string
.it will create one object..but in scjp 6
book author is saying there will be 2
objects , one in string pool and second
is in heap. see this link also
‘http://www.coderanch.com/t/245707/ja
va-programmer-
SCJP/certi cation/String-object-
created’
(http://www.coderanch.com/t/245707/ja
va-programmer-
SCJP/certi cation/String-object-
created%27) .. please elaborate this
string concept
Reply
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 44/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
Hi pankaj,
Thanks a lot for providing examples
and good explanations.if you have stu
about GWT framework(Google Web
Toolkit) please post that frame work
concepts too.it will be really help to for
those who new to this framework
Reply
dinesh says:
February 3, 2014 at 6:03 am
Pankaj says:
August 15, 2013 at 8:43 pm
Hi pankaj ,
your stu regarding strings in java is
really great . it is really helpful in
prospective of interviews and gaining
some knowledge over java strings ..
Loved it ..Keep up good work buddy!!!
Reply
Reply
Nice Material….
Keep it up to make us knowledgeable..
Reply
Hi Pankaj,
There is always something new to learn
in your posts.
But I would like to correct one thing in
above post.
When we create a String using new
keyword, a whole new reference is
being assigned, not from a literal. Up to
this its right. But this instance is not
added into the String Pool until we call
intern(). We can check it out by below
example:
Pankaj says:
September 10, 2013 at 5:34 pm
deepak
August says:
31, 2016 at 11:20 pm
Hi
I’ve a query!!
please correct me if I’m wrong.
String s = new String(“Hello”);
When above code is executed two
objects will be created. One in
heap another in SCP(String
Constant Pool)
So what is the need to use intern()
explicitly.? Or when do we use
intern() exactly??
by above discussion i got that
object will not be added to SCP
but its created.!! then where it is
created.?
Reply
Rhicha January
says: 13, 2019 at 10:26 pm
siddu says:
October 13, 2013 at 7:49 pm
Deepak Chauhan
November 14, 2013 at says:
6:28 pm
Paramjeet says:
September 13, 2014 at 11:55 pm
Singh
String s=new
String(“Deepak”);
when u have create
a String object by
using new keword
than every time Previous Next
create new object
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 49/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
in heap;
but by using literal
String than check
in the memory
but here there are
two object is
created
one is heap , and
second in pool;
public class java {
public static void
main(String arr[])
{
String s=new
String(“Deepak”);
String
s1=”Deepak”;
String s2=new
String(“Deepak”);
System.out.println(
s==s2);
System.out.println(
s==s1);
}
}
output is false
false
that is solution
Leave a Reply
Your email address will not be published.
Required elds are marked *
Comment
Name * Email *
Post Comment
Previous Next
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 50/51
11/22/2019 Java String Interview Questions and Answers - JournalDev
tutorials. Mkyong
Java Interview
JournalDev was founded by Pankaj Questions
Python Tutorials
Kumar in 2010 to share his
experience and learnings with the Core Java Interview
Questions JavaString
whole world. He loves Open source
technologies and writing on
Java Design Patterns Resources
JournalDev has become his passion.
Spring Tutorial
https://www.journaldev.com/1321/java-string-interview-questions-and-answers 51/51