Answers for "java fill list"

1

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]
Posted by: Guest on November-11-2020
1

how to fill a list with a single value java

//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;
}
Posted by: Guest on April-24-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language