List of usage examples for java.util Collections copy
public static <T> void copy(List<? super T> dest, List<? extends T> src)
From source file:MainClass.java
public static void main(String[] a) { List l1 = Arrays.asList(new String[] { "A", "B", "C" }); List l2 = Arrays.asList(new String[] { "A", "C", "D" }); Collections.copy(l1, l2); // works Collections.copy(l2, l1); // System.out.println(l1);/*from w ww. jav a 2 s.c om*/ System.out.println(l2); }
From source file:Main.java
public static void main(String[] args) { Vector<String> v1 = new Vector<String>(); v1.add("1");/*w w w. j a v a 2s . com*/ v1.add("2"); v1.add("3"); Vector<String> v2 = new Vector<String>(); v2.add("One"); v2.add("Two"); v2.add("Three"); v2.add("Four"); v2.add("Five"); System.out.println(v2); Collections.copy(v2, v1); System.out.println(v2); }
From source file:Main.java
public static void main(String[] args) { String[] coins = { "A", "B", "C", "D", "E" }; List src = new LinkedList(); for (int i = 0; i < coins.length; i++) src.add(coins[i]);//from w w w . j a v a2 s. c o m List dst = new ArrayList(); for (int i = 0; i < coins.length; i++) dst.add(""); Collections.copy(dst, src); ListIterator liter = dst.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:MainClass.java
public static void main(String[] args) { String[] coins = { "A", "B", "C", "D", "E" }; List src = new LinkedList(); for (int i = 0; i < coins.length; i++) src.add(coins[i]);/*from w w w .j a va 2s . c o m*/ List dst = new ArrayList(); for (int i = 0; i < coins.length; i++) dst.add(""); Collections.copy(dst, src); ListIterator liter = dst.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); Collections.fill(src, "no coins"); liter = src.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("1");/*w ww . jav a 2 s .c o m*/ v.add("2"); v.add("3"); ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("One"); arrayList.add("Two"); arrayList.add("Three"); arrayList.add("Four"); arrayList.add("Five"); System.out.println(arrayList); Collections.copy(arrayList, v); System.out.println(arrayList); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { List wineMakers = Arrays.asList(new String[] { "U", "C" }); List barFlies = Arrays.asList(new String[] { "U", "C", "L" }); Collections.copy(barFlies, wineMakers); System.out.println(barFlies); Collections.copy(wineMakers, barFlies); }
From source file:Main.java
public static void main(String args[]) { List<String> srclst = new ArrayList<String>(5); List<String> destlst = new ArrayList<String>(10); // populate two lists srclst.add("tutorial"); srclst.add("from"); srclst.add("java2s.com"); destlst.add("Java Tutorial"); destlst.add("From"); destlst.add("Java2s.com"); // copy into dest list Collections.copy(destlst, srclst); System.out.println("Value of source list: " + srclst); System.out.println("Value of destination list: " + destlst); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrayList1 = new ArrayList<String>(); arrayList1.add("1"); arrayList1.add("2"); arrayList1.add("3"); ArrayList<String> arrayList2 = new ArrayList<String>(); arrayList2.add("One"); arrayList2.add("Two"); arrayList2.add("Three"); arrayList2.add("Four"); arrayList2.add("Five"); System.out.println(arrayList2); Collections.copy(arrayList2, arrayList1); System.out.println(arrayList2); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); Vector<String> v = new Vector<String>(); v.add("A");/* w w w.j a v a 2 s.c o m*/ v.add("B"); v.add("D"); v.add("E"); v.add("F"); v.add("G"); v.add("H"); System.out.println(v); Collections.copy(v, arrayList); System.out.println(v); }
From source file:Utilities.java
public static void main(String[] args) { List list = Arrays.asList("one Two three Four five six one".split(" ")); System.out.println(list);//from ww w.j a va 2 s . c o m System.out.println("max: " + Collections.max(list)); System.out.println("min: " + Collections.min(list)); AlphabeticComparator comp = new AlphabeticComparator(); System.out.println("max w/ comparator: " + Collections.max(list, comp)); System.out.println("min w/ comparator: " + Collections.min(list, comp)); List sublist = Arrays.asList("Four five six".split(" ")); System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist)); System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist)); Collections.replaceAll(list, "one", "Yo"); System.out.println("replaceAll: " + list); Collections.reverse(list); System.out.println("reverse: " + list); Collections.rotate(list, 3); System.out.println("rotate: " + list); List source = Arrays.asList("in the matrix".split(" ")); Collections.copy(list, source); System.out.println("copy: " + list); Collections.swap(list, 0, list.size() - 1); System.out.println("swap: " + list); Collections.fill(list, "pop"); System.out.println("fill: " + list); List dups = Collections.nCopies(3, "snap"); System.out.println("dups: " + dups); // Getting an old-style Enumeration: Enumeration e = Collections.enumeration(dups); Vector v = new Vector(); while (e.hasMoreElements()) v.addElement(e.nextElement()); // Converting an old-style Vector // to a List via an Enumeration: ArrayList arrayList = Collections.list(v.elements()); System.out.println("arrayList: " + arrayList); }