Questions
Which of the following methods is/are defined in the String class for comparing the Strings?
- equals(String s)
- compareToIgnoreCase(String s1)
- compareTo(String s3)
- both 2 and 3
- all of these
String s = “Welcome To Java” s.substring(4 , 3 );
What will be the result of the above code?
- ome
- - 1
- com
- run time error
- compile time error
String s = “Welcome To Java”; String s1 = “Java”; s.match(s1);
What will be the output of the given code?
- true
- false
- - 1
- compile time error
- run time error
Which of the following functions cannot be invoked using the object of String class?
- toLower()
- trim()
- split()
- both 1 and 3
- both 2 and 3
String s1 = “abc”; String s2= “abg”; S1.compareTo(s2);
What will be result of the above code?
- - 4
- 4
- - 1
- 1
- 0
Which of the following methods is/are provided by the Character class?
- isDigit()
- isLetter()
- isLetterOrDigit()
- all of these
- none of these
String s = “Welcome To Java” s.lastIndexOf(“Java”,5);
What is the result of the given code?
- - 1
- 11
- 6
- Compiler error : method lastIndexOf() not declared
- Compiler error : parameters to method not sufficient
String s = “Welcome To Java”; s.charAt(s.length());
What will be the result of the above code?
- a
- v
- compiler error : cannot pass a function as parameter
- compiler error : parameters not sufficient
- runtime error
StringBuffer s = new StringBuffer(“Hello”); s.capacity();
What will be returned by the function capacity()?
- 16
- 4
- 18
- 3
- 15
Which of the following functions is/are valid in Java for Strings?
- valueOf()
- toCharArray()
- toIntArray()
- both 1 and 2
- both 1 and 3
Which of the following methods cannot be used with the object of String class?
- replace(char , char)
- replaceAll(String , String)
- append(String)
- both 1 and 2
- all of these
Which of the following data types can be passed as the first parameter to the lastIndexOf() method in the String class?
- Char
- String
- Int
- Both 1 and 2
- All of the above
StringBuffer s = new StringBuffer(“Welcome To Java”); s.delete(8,12);
What will be the output of the given code segment?
- Welcome ava
- Welcome va
- Welcomeava
- Compiler error : delete cannot be used with StrinBuffer
- Run time error
String s = “Welcome To Java”; s.length(); s.charAt(9);
What will be the output of the given code?
- s.length() = 14s.charAt(9) = T
- s.length() = 15s.charAt(9) = o
- s.length() = 15s.charAt(9) = T
- s.length() = 14s.charAt(9) = o
- compiler error
String s = “Welcome To Java” s.substring(4 , 4 );
What will be the outcome of the given code?
- o
- c
- empty string
- compile time error
- run time error