0% found this document useful (0 votes)
2 views

chapter String hanling

The document contains a series of questions and options related to Java String manipulation and methods. It covers topics such as substring extraction, method return types, and characteristics of String objects. Additionally, it includes true/false statements and multiple-choice questions about String class functionalities.

Uploaded by

asitakumar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

chapter String hanling

The document contains a series of questions and options related to Java String manipulation and methods. It covers topics such as substring extraction, method return types, and characteristics of String objects. Additionally, it includes true/false statements and multiple-choice questions about String class functionalities.

Uploaded by

asitakumar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1) .

Given a string str=CompuTerScieNceand ENGINEERING”; The output of


str.substring(5,12) will return ______ characters

Options

(a) 6
(b) 7
(c) 8
(d) 9

2) The following code will produce output as :

Options

public class Exam


{
public static void main(String[] args)
{
String s="ICSE2021";
system.out.println
(s.substring(4)+s.length());
}
}
Options
(a) 20218
(b) 2029
(c) Error
(d) 2030

3) . Write the return data type of the following functions :


(i) startsWith( )
(ii) random( )

4) The trim() method of the String class removes ............... .


1. leading spaces only
2. trailing spaces only
3. spaces in between words
4. leading and trailing spaces
5) While using the toLowerCase() method on a string containing special
characters, ............... .
1. the special characters remain unaffected.
2. the special characters are converted to spaces.
3. the special characters are converted to null character.
4. the special characters are removed from the string.
6)The index of a string ............... .
1. ranges from 0 to the length -1 of the string
2. ranges from 0 to the length of the string
3. ranges from 1 to the length of the string
4. ranges from 1 to the length -1 of the string
7) The indexOf() method returns the position of the ............... .
1. first occurrence of the specified character
2. last occurrence of the specified character
3. null character
4. '\n' character
8) The return type of the equals() method is ............... .
1. int
2. char
3. boolean
4. void
9) Which one of the given statements is true for the following statement?
string1.compareTo(string2)
1. if string1 > string2 the result will be a negative integer i.e. < 0.
2. if string1 > string2 the result will be a positive integer i.e. > 0.
3. if string1 > string2 the result will be 0.
4. None of the above
10)Which one of the given statements is true for the following statement?
string1.compareTo(string2)
1. if string1 > string2 the result will be a positive integer i.e. > 0.
2. if string1 < string2 the result will be a negative integer i.e. < 0.
3. if string1 = string2 the result will be 0 i.e. = 0.
4. all of these
11) The valueOf() method returns the ............... .
1. string representation of the argument
2. int representation of the argument
3. boolean representation of the argument
4. character representation of the argument
12)Output of the following statement is ............... .
System.out.println("SUNDAY".substring(3));
1. NDA
2. DAY
3. SUN
4. N
13) Output of the following statement is ............... .
System.out.println("WONDERFUL".substring(3,4));
1. DERF
2. NDER
3. D
4. N
14) A String object cannot be modified after it is created. (T/F)
15) The length of a String object s1 can be obtained using the expression s1
length.
16)Which of the following methods belong to the String class ?
1. length()
2. compareTo()
3. equals()
4. substring()
5. All of these
6. None of them
17)Given the code
String s1 = "yes" ;
String s2 = "yes" ;
String s3 = new String(s1) ;
Which of the following would equate to False ?
1. s1 == s2
2. s3 == s1
3. s1.equals(s2)
18) Suppose that s1 and s2 are two strings. Which of the statements or
expressions are incorrect ?
1. String s3 = s1 + s2;
2. String s3 = s1 - s2;
3. s1.compareTo(s2);
4. int m = s1.length( );
19)Given the code :
String s = new String("abc");
Which of the following calls are invalid ?
1. s.trim( )
2. s.replace('a', 'A')
3. s.substring(3)
4. s.toUpperCase( )
5. s.setCharAt(1, 'A')
20)Which of these class is superclass of String and StringBuffer class?
1. java.util
2. java.lang
3. ArrayList
4. None of the mentioned
21)Which of these methods of class String is used to obtain length of String
object?
1. get( )
2. Sizeof( )
3. lengthof( )
4. length( )
22)Which of these methods of class String is used to extract a single character
from a String object?
1. CHARAT( )
2. chatat( )
3. charAt( )
4. ChatAt( )
23)Which of these constructors is used to create an empty String object?
1. String( )
2. String(void)
3. String(0)
4. None of the mentioned
24)Which of these is an incorrect statement?
1. String objects are immutable, they cannot be changed.
2. When you assign a new value to a String object, Java internally creates
another String object.
3. StringBuffer is a mutable class that can store sequence of characters.
4. String objects are actually arrays of characters.

You might also like