Answers for "filled in java"

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
4

arrays.fill java

import java.util.Arrays;
int[] myArray = new int[10];
Arrays.fill(myArray,1);//This will fill the array with 1s
Posted by: Guest on April-06-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language