Java Code Examples for java.util.Collections.copy()

The following are Jave code examples for showing how to use copy() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: KernelHive   File: GenericGraphNode.java   View Source Code Vote up 5 votes
private void disconnectPreviousNodes(final IGraphNode node) {
	final List<IGraphNode> list = new ArrayList<IGraphNode>(
			node.getPreviousNodes());
	Collections.copy(list, node.getPreviousNodes());
	for (final IGraphNode pNode : list) {
		node.removePreviousNode(pNode);
	}
}
 
Example 2
Project: KernelHive   File: GenericGraphNode.java   View Source Code Vote up 5 votes
private void disconnectFollowingNodes(final IGraphNode node) {
	final List<IGraphNode> list = new ArrayList<IGraphNode>(
			node.getFollowingNodes());
	Collections.copy(list, node.getFollowingNodes());
	for (final IGraphNode fNode : list) {
		node.removeFollowingNode(fNode);
	}
}
 
Example 3
Project: KernelHive   File: GenericGraphNode.java   View Source Code Vote up 5 votes
private void disconnectPreviousNodes(IGraphNode node) {
	List<IGraphNode> list = new ArrayList<IGraphNode>(
			node.getPreviousNodes());
	Collections.copy(list, node.getPreviousNodes());
	for (IGraphNode pNode : list) {
		node.removePreviousNode(pNode);
	}
}
 
Example 4
Project: KernelHive   File: GenericGraphNode.java   View Source Code Vote up 5 votes
private void disconnectFollowingNodes(IGraphNode node) {
	List<IGraphNode> list = new ArrayList<IGraphNode>(
			node.getFollowingNodes());
	Collections.copy(list, node.getFollowingNodes());
	for (IGraphNode fNode : list) {
		node.removeFollowingNode(fNode);
	}
}
 
Example 5
Project: LivroJavaComoProgramar10Edicao   File: Algorithms1.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{
   // create and display a List< Character >
   Character[] letters = {'P', 'C', 'M'};
   List<Character> list = Arrays.asList(letters); // get List
   System.out.println("list contains: ");
   output(list);

   // reverse and display the List<Character>
   Collections.reverse(list); // reverse order the elements
   System.out.printf("%nAfter calling reverse, list contains:%n");
   output(list);

   // create copyList from an array of 3 Characters
   Character[] lettersCopy = new Character[3]; 
   List<Character> copyList = Arrays.asList(lettersCopy); 

   // copy the contents of list into copyList
   Collections.copy(copyList, list);
   System.out.printf("%nAfter copying, copyList contains:%n");
   output(copyList);

   // fill list with Rs 
   Collections.fill(list, 'R'); 
   System.out.printf("%nAfter calling fill, list contains:%n");
   output(list);
}
 
Example 6
Project: werewolf_server   File: ListTest.java   View Source Code Vote up 5 votes
@Test
public void test(){

    List<String> src = new ArrayList<>();
    src.add("asd");
    List<String> dest = new ArrayList<>(Arrays.asList(new String[src.size()]));
    Collections.copy(dest,src);
    System.out.println(dest);

}
 
Example 7
Project: bdf2   File: DataType.java   View Source Code Vote up 5 votes
private static List<DataType> getDataTypeListCopy(List<DataType> dataTypeList) {
	List<DataType> dataTypeListCopy = new ArrayList<DataType>();
	for(int i = 0; i<dataTypeList.size(); i++){
		dataTypeListCopy.add(null);
	}
	Collections.copy(dataTypeListCopy, dataTypeList);
	return dataTypeListCopy;
}
 
Example 8
Project: AOSP-Kayboard-7.1.2   File: WordComposer.java   View Source Code Vote up 5 votes
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord) {
    mEvents.clear();
    Collections.copy(mEvents, lastComposedWord.mEvents);
    mInputPointers.set(lastComposedWord.mInputPointers);
    mCombinerChain.reset();
    refreshTypedWordCache();
    mCapitalizedMode = lastComposedWord.mCapitalizedMode;
    mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
    mCursorPositionWithinWord = mCodePointSize;
    mRejectedBatchModeSuggestion = null;
    mIsResumed = true;
}
 
Example 9
Project: javaide   File: CopyElementsOfVectorToVectorExample.java   View Source Code Vote up 4 votes
public static void main(String[] args) {

    //create first Vector object
    Vector v1 = new Vector();

    //Add elements to Vector
    v1.add("1");
    v1.add("2");
    v1.add("3");

    //create another Vector object
    Vector v2 = new Vector();

    //Add elements to Vector
    v2.add("One");
    v2.add("Two");
    v2.add("Three");
    v2.add("Four");
    v2.add("Five");

    /*
      To copy elements of one Java Vector to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy, Second Vector Contains : " + v2);

    //copy all elements of Vector to another Vector using copy
    //method of Collections class
    Collections.copy(v2, v1);

    /*
      Please note that, If destination Vector object is not long enough
      to hold all elements of source Vector,
      it throws IndexOutOfBoundsException.
    */

    System.out.println("After copy, Second Vector Contains : " + v2);
  }
 
Example 10
Project: javaide   File: CopyElementsOfVectorToArrayListExample.java   View Source Code Vote up 4 votes
public static void main(String[] args) {

    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("1");
    v.add("2");
    v.add("3");

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("One");
    arrayList.add("Two");
    arrayList.add("Three");
    arrayList.add("Four");
    arrayList.add("Five");

    /*
      To copy elements of Java Vector to Java ArrayList use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy ArrayList Contains : " + arrayList);

    //copy all elements of Vector to ArrayList using copy method of Collections class
    Collections.copy(arrayList, v);

    /*
      Please note that, If ArrayList is not long enough to hold all elements of
      Vector, it throws IndexOutOfBoundsException.
    */

    System.out.println("After Copy ArrayList Contains : " + arrayList);
  }
 
Example 11
Project: javaide   File: CopyElementsOfArrayListToVectorExample.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
  //create an ArrayList object
  ArrayList arrayList = new ArrayList();

  //Add elements to Arraylist
  arrayList.add("1");
  arrayList.add("4");
  arrayList.add("2");
  arrayList.add("5");
  arrayList.add("3");

  //create a Vector object
  Vector v = new Vector();

  //Add elements to Vector
  v.add("A");
  v.add("B");
  v.add("D");
  v.add("E");
  v.add("F");
  v.add("G");
  v.add("H");

  /*
    To copy elements of Java ArrayList to Java Vector use,
    static void copy(List dstList, List sourceList) method of Collections class.

    This method copies all elements of source list to destination list. After copy
    index of the elements in both source and destination lists would be identical.

    The destination list must be long enough to hold all copied elements. If it is
    longer than that, the rest of the destination list's elments would remain
    unaffected.
  */

  System.out.println("Before copy, Vector Contains : " + v);

  //copy all elements of ArrayList to Vector using copy method of Collections class
  Collections.copy(v, arrayList);

  /*
     Please note that, If Vector is not long enough to hold all elements of
     ArrayList, it throws IndexOutOfBoundsException.
  */

  System.out.println("After Copy, Vector Contains : " + v);
}
 
Example 12
Project: javaide   File: CopyElementsOfArrayListToArrayListExample.java   View Source Code Vote up 4 votes
public static void main(String[] args) {

    //create first ArrayList object
    ArrayList arrayList1 = new ArrayList();

    //Add elements to ArrayList
    arrayList1.add("1");
    arrayList1.add("2");
    arrayList1.add("3");

    //create another ArrayList object
    ArrayList arrayList2 = new ArrayList();

    //Add elements to Arraylist
    arrayList2.add("One");
    arrayList2.add("Two");
    arrayList2.add("Three");
    arrayList2.add("Four");
    arrayList2.add("Five");

    /*
      To copy elements of one Java ArrayList to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy, Second ArrayList Contains : " + arrayList2);

    //copy all elements of ArrayList to another ArrayList using copy
    //method of Collections class
    Collections.copy(arrayList2, arrayList1);

    /*
      Please note that, If destination ArrayList object is not long
      enough to hold all elements of source ArrayList,
      it throws IndexOutOfBoundsException.
    */

    System.out.println("After copy, Second ArrayList Contains : " + arrayList2);
  }
 
Example 13
Project: MyAnimeViewer   File: EpisodeRecyclerAdapter.java   View Source Code Vote up 4 votes
public EpisodeRecyclerAdapter(Context context, List<Episode> episodes, OnItemClickListener itemClickListener) {
    this.context = context;
    this.itemClickListener = itemClickListener;
    list = episodes;
    Collections.copy(list, result);
}
 
Example 14
Project: jpl-framework   File: CollectionsUtils.java   View Source Code Vote up 2 votes
/**
 * Returns a deep copy of the given list.
 * 
 * @param <T> the type of the list to copy
 * 
 * @param listToCopy the list to copy
 * @return a copy of the given list
 */
public static <T> List<T> getDeepCopyOf(List<T> listToCopy) {
   List<T> copy = new ArrayList<>(listToCopy);
   Collections.copy(copy, listToCopy);
   return copy;
}