JAVA
2.7K subscribers
73 photos
111 files
76 links
Download Telegram
The default capacity of a ArrayList is:
Anonymous Quiz
12%
12
26%
16
21%
1
40%
10
Which provides better performance for the insertion and removal from the middle of the list?
Anonymous Quiz
6%
Vector
31%
ArrayList
40%
LinkedList
23%
All of these
import java.util.Arrays;
import java.util.Comparator;
class Sort implements Comparator<Integer>{
public int compare(Integer o1,Integer o2){
return o2.compareTo(o1);
}
}
public class Program
{
public static void main(String[] args) {
Integer intArray[]={2,3,1};
Arrays.sort(intArray,new Sort());
for(int i: intArray ){
System.out.print(i+" ");
}
}
}
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Program
{
public static void main(String[] args) {
Set set=new TreeSet();
set.add(1);
set.add("2");
set.add(3);
Iterator iterator=set.iterator();

while(iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
}
}
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