String Handling


1.Which package does define String and StringBuffer classes?

java.lang package.

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

length( ) method.

3.How do you concatenate Strings?

By using " + " operator.

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

equals( ) method.

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

equalsIgnoreCase( ) method.

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

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

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

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.

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

capacity( ) method.

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

setLength( ).

10.What is the difference between String and StringBuffer?

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