java fill list
// -- Filling with fill() method example:
List<String> arrlist = new ArrayList<String>();
//Add elements in the list
arrlist.add("one");
arrlist.add("two");
arrlist.add("three");
// contents of list: [AAA, BBB, CCC]
//Fill the list with 'four'
Collections.fill(arrlist,"four");
// contents of list: [four, four, four]
// -- Second example
List<Integer> arrList = Arrays.asList(1,2,3,4);
//Fill the list with 551
Collections.fill(arrList,42);
// contents of list: [42, 42, 42]
3
1
//x is the list and value is what it is to be set to
for (int i = 0; i < x.length; i++) {
x[i] = value;
}
Thank you!
1
0
Are there any code examples left?
New code examples in category Java