Java List fill value

Description

Java List fill value


import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    String[] langArray = { "CSS", "HTML", "C++", "Dart", "SQL" };

    List<String> list = new LinkedList<>();
    for (int i = 0; i < langArray.length; i++){
      list.add(langArray[i]);/*from w w  w .j a  va  2 s .com*/
    }

    System.out.println(list);
   
    Collections.fill(list, "demo2s.com");

    Iterator<String> liter = list.listIterator();

    while (liter.hasNext())
      System.out.println(liter.next());
    
    list.add("new value");

    System.out.println(list);
  }
}



PreviousNext

Related