Arrays and Strings

Arrays and Strings

11 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

How many string objects are created by the given statement?
String str=new String(“Aliens”);

  1. 0
  2. 1
  3. 2
  4. 4
Question 2 Multiple Choice (Single Answer)

What will be the value of “str” after executing the following statements?
StringBuffer str=new StringBuffer(“I am a student”);
str.delete(2,6);

  1. I student
  2. Istudent
  3. Itudent
  4. I am a student
Question 3 Multiple Choice (Single Answer)

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.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 4 Multiple Choice (Single Answer)

What is the size and capacity of the Vector Num in the following code?
Vector Num=new Vector(10)

  1. Size = 10, capacity = 0
  2. Size = 0, capacity = 10
  3. Size = 10, capacity = 10
  4. Size = 0, capacity = 0
Question 5 Multiple Choice (Single Answer)

Which of the following methods is used to convert a given string to a new character array?

  1. toArray()
  2. StringToArray()
  3. toCharArray()
  4. toCArray()
Question 6 Multiple Choice (Single Answer)

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);

  1. 0
  2. 1
  3. -1
  4. +1
Question 7 Multiple Choice (Single Answer)

What does the startIndex and endIndex argument in delete() method of StringBuffer class specify?

  1. Deletion of characters from startIndex position to endIndex position
  2. Deletion of characters from startIndex position to endIndex-1 position
  3. Deletion of all the characters
  4. Deletion of the startIndex and endIndex characters only
  5. Deletion of a single character only
Question 8 Multiple Choice (Single Answer)

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);

  1. The value of i will be 4 and the value of ch will be ’s’.
  2. The value of i will be 3 and the value of ch will be ’h’.
  3. The value of i will be 3 and the value of ch will be ’s’.
  4. The value of i will be 4 and the value of ch will be ’h’.
Question 9 Multiple Choice (Single Answer)

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";
}

}

  1. slip stream
  2. slipstream stream
  3. stream slip stream
  4. slipstream slip stream
Question 10 Multiple Choice (Single Answer)

What is the correct syntax of replace() method of the StringBuffer class?

  1. StringBuffer replace(int s,int e)
  2. StringBuffer replace(int s,String str)
  3. StringBuffer replace(int s,String str1,String str2)
  4. StringBuffer replace(int s,int e,String str)
Question 11 Multiple Choice (Single Answer)

Which of the following statement(s) is/are correct?
A. valueOf() is a static method.
B. toString() is overridden in Integer and Double Class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B