Top 20 String qstns Flashcards

1
Q
  1. What is String in Java? Is it a datatype?
A

..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What is the difference between String in C language and String in Java?**
A

..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What is the String pool in Java?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Why String is immutable?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. How many objects will be created from the following code?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is theintern()method?**
A

..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What is the difference between the**StringandStringBuffer?
A

..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What is the difference between the**StringBufferandStringBuilder?
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Can we compare String using the==operator? What is the risk?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What are the ways to compare string?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. What is the use of thesubstring()method?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. How to check if the String is empty?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. What is theformat()method in Java String? What is the difference between theformat()method and theprintf()method?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. Why most of the time string is used asHashMapkey?**
A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. Can you convert String to Int and vice versa?**
A

.

17
Q
  1. What is thesplit()method?**
A

.

18
Q
  1. What is the difference between"Gaurav Kukade".equals(str)andstr.equals("Gaurav Kukade")?**
    .
A

.

19
Q
  1. Can we use a string in switch case in java?**
A

.

20
Q
  1. How string concatenation using the+operator works in Java?**
A

+operator is the only overloaded operator. You can use it for both adding two numbers as well as for string concatenation purposes.

If you are using the Java version 1.5 or above, string concatenation internally uses the`append()`method of the`StringBuilder`. And for versions lower than 1.5, it uses the`append()`method of the`StringBuffer`class