Subject : How to add an element to List while initializing a List in Java
Solution :
List<Integer> idList = Arrays.asList(121,121,3434);
List<String> nameList = Arrays.asList("Ravi","Bob");
As you all knew, List is an interface and ArrayList is a class that implements List interface. It is best practice to create an instance for ArrayList using List Interface as shown in below example
List<String> strList = new ArrayList<String>();
Solution :
List<Integer> idList = Arrays.asList(121,121,3434);
List<String> nameList = Arrays.asList("Ravi","Bob");
As you all knew, List is an interface and ArrayList is a class that implements List interface. It is best practice to create an instance for ArrayList using List Interface as shown in below example
List<String> strList = new ArrayList<String>();
No comments:
Post a Comment