JAVA
2.7K subscribers
73 photos
111 files
76 links
Download Telegram
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Program
{
public static void main(String[] args) {
List<String> arrayList=new ArrayList<String>();
arrayList.add("a");
arrayList.add("b");
Iterator<String> iterator= arrayList.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
arrayList.add("c");
}
}
}
An unordered array has a search time complexity of:
Anonymous Quiz
33%
O(log n)
24%
O(n)
39%
O(n+1)
3%
O(1)
The add and remove method in TreeSet have a time complexity of:
Anonymous Quiz
7%
O(n)
34%
O(n+1)
31%
O(1)
28%
O(log n)
After resizing, size of ArrayList is increased by :
Anonymous Quiz
22%
200%
41%
50%
31%
100%
6%
None of these
After resizing, size of Vector is increased by:
Anonymous Quiz
9%
200%
44%
100%
31%
50%
16%
None of these
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
public class Program
{
public static void main(String[] args) {
Vector<String> vector=new Vector<String>();
vector.add("1");
vector.add("2");
Enumeration<String> listEnum= Collections.enumeration(vector);
while(listEnum.hasMoreElements()){
vector.add("3"); System.out.println(listEnum.nextElement());

}
}
}
Deque and Queue are derived from:
Anonymous Quiz
6%
AbstractList
45%
Collection
26%
AbstractCollection
23%
List
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
class Employee{
String name;
public Employee(){}
public Employee(String name){
this.name=name;
}
public String toString(){
return "name"+name;
}
static class comparatorName implements Comparator<Employee>{
public int compare(Employee obj1,Employee obj2){
return obj1.name.compareTo(obj2.name);
}
}
}
public class Program
{
public static void main(String[] args) {
Employee e1=new Employee("ankit");
Employee e2=new Employee("brad");

ArrayList<Employee> list=new ArrayList<Employee>();
list.add(e1);
list.add(e2);
Collections.sort(list,new Employee.comparatorName());
System.out.println(list);
}
}
What guarantees type-safety in a collection?
Anonymous Quiz
42%
Generics
26%
Abstract classes
29%
Interface
3%
Collection
HashSet internally uses?
Anonymous Quiz
32%
Set
56%
HashMap
7%
List
5%
Collection
The most used interfaces from the Collection framework are?
Anonymous Quiz
23%
List
15%
Map
5%
Set
56%
All of these
The root interface of Java Collection framework hierarchy is -
Anonymous Quiz
51%
Collection
5%
Root
35%
Collections
8%
List/Set
Which of these is synchronized?
Anonymous Quiz
13%
ArrayList
38%
LinkedList
33%
Vector
18%
None of these
ArrayList implements which of the following?
Anonymous Quiz
32%
List
18%
RandomAccess
13%
Cloneable
37%
All of these
Which of these allows the storage of many null values?
Anonymous Quiz
5%
Set
55%
List
21%
None of these
18%
All of these
nextIndex() and previousIndex() are methods of which interface?
Anonymous Quiz
13%
IndexIterator
23%
Iterator
48%
ListIterator
16%
NextPreviousIterator
Vector extends which of these?
Anonymous Quiz
19%
ArrayList
25%
LinkedList
42%
AbstractList
14%
None