Top 20 String qstns Flashcards
1
Q
- What is String in Java? Is it a datatype?
A
..
2
Q
- What is the difference between String in C language and String in Java?**
A
..
3
Q
- What is the String pool in Java?**
A
.
4
Q
- Why String is immutable?**
A
.
5
Q
- How many objects will be created from the following code?**
A
.
6
Q
- What is the
intern()
method?**
A
..
7
Q
- What is the difference between the**
String
andStringBuffer
?
A
..
8
Q
- What is the difference between the**
StringBuffer
andStringBuilder
?
A
.
9
Q
- Can we compare String using the
==
operator? What is the risk?**
A
.
10
Q
- What are the ways to compare string?**
A
.
11
Q
- What is the use of the
substring()
method?**
A
.
12
Q
- How to check if the String is empty?**
A
.
13
Q
- What is the
format()
method in Java String? What is the difference between theformat()
method and theprintf()
method?**
A
.
14
Q
- Can you say String is ‘thread-safe’ in Java?**
A
Yes, we can say that the string is thread-safe.
As we know, String is immutable in Java. That means once we created a string, we can not modify it afterword. Hence there is no issue of multiple threads accessing a string object.
15
Q
- Why most of the time string is used as
HashMap
key?**
A
.