Java Collections and Strings

Questions covering Java Collections Framework (ArrayList, Stack, LinkedList, Vector, Queue) and String class methods and operations

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

How many constructors are there of ArrayList class in Java?

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

Which of the following methods is present in the Stack class in Java Collections framework?

  1. remove()
  2. element()
  3. Pop()
  4. poll()
  5. exit()
Question 3 Multiple Choice (Single Answer)

Which of the following methods is present in LinkedList class in Java Collections?

  1. addFirst()
  2. setFirst()
  3. setLast()
  4. indexOf(e:Element)
  5. lastIndexOf(e:element)
Question 4 Multiple Choice (Single Answer)

Which of the following methods is/are static in Collections class?

  1. Frequency(c : collection, o : object)
  2. Reverse(List)
  3. Sort(List)
  4. Both (1) and (2)
  5. All of the above
Question 5 Multiple Choice (Single Answer)

Which of the following methods are present in the queue interface?

  1. poll()
  2. search(o:Object)
  3. empty()
  4. exit()
  5. pop()
Question 6 Multiple Choice (Single Answer)

Which of the following methods is/are not present in Vector class in Java Collections framework?

  1. elementAt(index)
  2. firstElement()
  3. removeElementAt(int)
  4. setSize(int)
  5. removeFirst()
Question 7 Multiple Choice (Single Answer)

What is the initial capacity of vector?

  1. 16
  2. 10
  3. 20
  4. 12
  5. 18
Question 8 Multiple Choice (Single Answer)

Which of the following methods in Collections class is not static?

  1. Min(c : collection)
  2. Shuffle(list)
  3. Frequency(c : collection, o : object)
  4. Copy(destination, source)
  5. Merge(c : collection, c1 : collection)
Question 9 Multiple Choice (Single Answer)

Which of the following methods is present in ListIterator interface in Java Collections?

  1. nextIndex()
  2. addAll()
  3. IndexOf()
  4. listIterator()
  5. subList(startindex,endindex)
Question 10 Multiple Choice (Single Answer)

Which of the following methods is/are defined in String class for comparing strings?

  1. equals(String s)
  2. compareToIgnoreCase(String s1)
  3. compareTo(String s3)
  4. Both (2) and (3)
  5. All of the above
Question 11 Multiple Choice (Single Answer)

How many constructors are there of Vector class in Java Collections framework?

  1. 6
  2. 5
  3. 4
  4. 3
  5. 2
Question 12 Multiple Choice (Single Answer)

Which of the following methods is present in Vector class in Java Collections framework?

  1. removeAllElements()
  2. element()
  3. removeLast()
  4. get(index : int)
  5. set(index,element)
Question 13 Multiple Choice (Single Answer)

What will be the output of the given code?

String s = “Welcome To Java” s.substring(4, 4);

  1. o
  2. c
  3. Empty string
  4. Compile time error
  5. Run time error
Question 14 Multiple Choice (Single Answer)

What will be the result of the following code?

String s = “Welcome To Java”; s.charAt(s.length());

  1. a
  2. v
  3. Compiler Error : cannot pass a function as parameter
  4. Compiler Error : parameters not sufficient
  5. Run time error
Question 15 Multiple Choice (Single Answer)

What will be the output of the given program?
class BitShift
{
public static
void main(String [] args)
{
int x = 0x80000000;
System.out.
print(x + and) ;
x = x >>> 31;
System.out.
println(x);
}
}

  1. -2147483648 and 1
  2. 0x80000000 and 0x00000001
  3. -2147483648 and -1
  4. 1 and -2147483648
  5. None of these