Subscribe Us

Core Java - Interview Questions and Answers

STRING HANDLING

301.Which package does define String and StringBuffer classes?

Ans : java.lang package.

302. Which method can be used to obtain the length of the String?

Ans : length( ) method.

303. How do you concatenate Strings?

Ans : By using " + " operator.

304. Which method can be used to compare two strings for equality?

Ans : equals( ) method.

305. Which method can be used to perform a comparison between strings that ignores case differences?

Ans : equalsIgnoreCase( ) method.

306. What is the use of valueOf( ) method?

Ans : valueOf( ) method converts data from its internal format into a human-readable form.

307. What are the uses of toLowerCase( ) and toUpperCase( ) methods?

Ans : The method toLowerCase( ) converts all the characters in a string from uppercase to
lowercase.
The method toUpperCase( ) converts all the characters in a string from lowercase to
uppercase.

308. Which method can be used to find out the total allocated capacity of a StrinBuffer?

Ans : capacity( ) method.

309. Which method can be used to set the length of the buffer within a StringBuffer object?

Ans : setLength( ).

310. What is the difference between String and StringBuffer?

Ans : String objects are constants, whereas StringBuffer objects are not.
String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings.

Post a Comment

0 Comments