Monday, July 25, 2016

How to store a default values in a List for a specific size


We can store a default values to the List interfcae implementation classes like ArrayList, LinkedList etc .
The storing a specific default value to the specific size of the array List implementation class is possible, Please check the below code for it.

Storing Integer values 0 as default value to the ArrayList of size 100;
      Integer intArray[] = new Integer[100];
      List al = new ArrayList(Arrays.asList(intArray));
      Collections.fill(al,0);
      System.out.println("ArrayList values are :"+al);
Storing String values "zameer" as default value to the ArrayList of size 100;
      String stArray[] = new String[100];
      List al = new ArrayList(Arrays.asList(stArray));
      Collections.fill(al,"zameer");
      System.out.println("ArrayList values are :"+al);
Please give us your comments on this article.

No comments:

Post a Comment