Click here to watch in Youtube :
https://www.youtube.com/watch?v=CK0efUCV3Xg&list=UUhwKlOVR041tngjerWxVccw
CollectionsExample.java
Output
https://www.youtube.com/watch?v=CK0efUCV3Xg&list=UUhwKlOVR041tngjerWxVccw
CollectionsExample.java
import java.util.ArrayList; import java.util.Collections; /* * Example of * copy(List<? super T> dest,List<? extends T> src) method */ public class CollectionsExample { public static void main(String[] args) { ArrayList<Integer> sourceList = new ArrayList<Integer>(); sourceList.add(1000); sourceList.add(2000); sourceList.add(3000); sourceList.add(4000); System.out.println("sourceList : " + sourceList + "\n"); ArrayList<Integer> destinationList = new ArrayList<Integer>(); destinationList.add(10); destinationList.add(20); destinationList.add(30); destinationList.add(40); System.out.println("destinationList : " + destinationList + "\n"); /* * Copies all of the elements from one list into another. After the * operation, the index of each copied element in the destination list * will be identical to its index in the source list. * * The destination list must be at least as long as the source list. If * it is longer, the remaining elements in the destination list are * unaffected. */ Collections.copy(destinationList, sourceList); System.out.println("destinationList After Copy: " + destinationList); } }
sourceList : [1000, 2000, 3000, 4000] destinationList : [10, 20, 30, 40] destinationList After Copy: [1000, 2000, 3000, 4000]
https://sites.google.com/site/javaee4321/java-collections/CollectionsDemoCopyApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment