+ 1
What will be default type if we don't provide specific type to ArrayList
2 Answers
+ 1
i think there is no default. You can use everything. This is about 'Generic Classes'
+ 1
Default type is String..
Example :
import java.util.ArrayList;
public class MyClass {
public static void main(String[ ] args) {
ArrayList <> numbers = new ArrayList <>();
numbers .add(2);
numbers .add(3);
System.out.println(numbers.get(0)); // accepted cause only printing // output : 2
System.out.println((numbers.get(0))+ 4); // not accepted unless array defined as Integer because of the add +
}
}