+ 1

What will be default type if we don't provide specific type to ArrayList

25th Jun 2016, 1:57 PM
Jigar Thacker
Jigar Thacker - avatar
2 Antworten
+ 1
i think there is no default. You can use everything. This is about 'Generic Classes'
25th Jun 2016, 8:01 PM
DanI MicraS
DanI MicraS - avatar
+ 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 + } }
27th Jun 2016, 1:42 PM
Fares Al Haddad
Fares Al Haddad - avatar