What will be the output of the following code?
List<String> list = new ArrayList<>();
list.add("Java");
System.out.println(list.get(0).length());
Q.202Easy
Which of the following is a valid generic method declaration?
Q.203Easy
What is the output of this generic code?
class Pair<K, V> {
public void display(K key, V value) {
System.out.println(key + ": " + value);
}
}
Pair<String, Integer> p = new Pair<>();
p.display("Age", 25);
Q.204Easy
In Java generics, what does the wildcard '?' represent?
Q.205Easy
What is the primary advantage of using generics in Java?
Advertisement
Q.206Easy
Which of the following will compile successfully?
Q.207Easy
What is the output of this code snippet?
ArrayList<String> list = new ArrayList<>();
list.add("Java");
Object obj = list.get(0);
String str = (String) obj;
System.out.println(str.length());
Q.208Easy
In the interface declaration 'interface Pair<K, V>', how many type parameters does it have?
Q.209Easy
Which of the following is a valid generic method declaration in Java?
Q.210Easy
What is the primary purpose of bounded type parameters in generics?
Q.211Easy
What will be the result of executing: List<Integer> list = new ArrayList<String>();
Q.212Easy
What is the output of the following code?
List<Integer> list = new ArrayList<Integer>();
list.add(10);
Object obj = list.get(0);
System.out.println(obj.getClass().getName());
Q.213Easy
What is the advantage of using generics over raw types in terms of 2024-25 Java standards?
Q.214Easy
Which of the following is a valid generic class declaration in Java?
Q.215Easy
What is the result of type erasure in Java generics?
Q.216Easy
What is the compiler-inferred type parameter in this call?
List<String> list = Arrays.asList("a", "b", "c");
Q.217Easy
What does the wildcard in List<?> represent?
Q.218Easy
What is the relationship between generics and arrays in Java?
Q.219Easy
What will be the output of the following code?
java
List<String> list = new ArrayList<String>();
list.add("Java");
Object obj = list;
System.out.println(list.getClass() == obj.getClass());
Q.220Easy
Which of the following correctly declares a generic method that returns the first element of any collection?