Questions
How many string objects are created by the given statement?
String str=new String(“Aliens”);
- 0
- 1
- 2
- 4
What will be the value of “str” after executing the following statements?
StringBuffer str=new StringBuffer(“I am a student”);
str.delete(2,6);
- I student
- Istudent
- Itudent
- I am a student
Which of the following statements is/are correct?
A. The size of a vector can grow or shrink.
B. The size of an array can grow or shrink.
- Only A
- Only B
- Both A and B
- Neither A nor B
What is the size and capacity of the Vector Num in the following code?
Vector Num=new Vector(10)
- Size = 10, capacity = 0
- Size = 0, capacity = 10
- Size = 10, capacity = 10
- Size = 0, capacity = 0
Which of the following methods is used to convert a given string to a new character array?
- toArray()
- StringToArray()
- toCharArray()
- toCArray()
What would be the value of i after the execution of the following statements in Java?
int i;
String st1=”Rakesh”;
String st2=”Roshan”;
i=st1.compareTo(st2);
- 0
- 1
- -1
- +1
What does the startIndex and endIndex argument in delete() method of StringBuffer class specify?
- Deletion of characters from startIndex position to endIndex position
- Deletion of characters from startIndex position to endIndex-1 position
- Deletion of all the characters
- Deletion of the startIndex and endIndex characters only
- Deletion of a single character only
What would be the value of i and ch after the execution of the following statements in Java?
int i;
char ch;
String st1=”Rakesh Roshan”;
i=st1.indexOf(‘e’);
ch=st1.charAt(5);
- The value of i will be 4 and the value of ch will be ’s’.
- The value of i will be 3 and the value of ch will be ’h’.
- The value of i will be 3 and the value of ch will be ’s’.
- The value of i will be 4 and the value of ch will be ’h’.
What will be the output of the program?
class PassS
{
public static void main(String [] args)
{
PassS p = new PassS();
p.start();
}
void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}
String fix(String s1)
{
s1 = s1 + "stream";
System.out.print(s1 + " ");
return "stream";
}
}
- slip stream
- slipstream stream
- stream slip stream
- slipstream slip stream
What is the correct syntax of replace() method of the StringBuffer class?
- StringBuffer replace(int s,int e)
- StringBuffer replace(int s,String str)
- StringBuffer replace(int s,String str1,String str2)
- StringBuffer replace(int s,int e,String str)
Which of the following statement(s) is/are correct?
A. valueOf() is a static method.
B. toString() is overridden in Integer and Double Class.
- Only A
- Only B
- Both A and B
- Neither A nor B