當前位置: 首頁>>代碼示例>>Java>>正文


Java Collections.copy方法代碼示例

本文整理匯總了Java中java.util.Collections.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java Collections.copy方法的具體用法?Java Collections.copy怎麽用?Java Collections.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.copy方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: disconnectPreviousNodes

import java.util.Collections; //導入方法依賴的package包/類
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);
	}
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:9,代碼來源:GenericGraphNode.java

示例2: disconnectFollowingNodes

import java.util.Collections; //導入方法依賴的package包/類
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);
	}
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:9,代碼來源:GenericGraphNode.java

示例3: disconnectPreviousNodes

import java.util.Collections; //導入方法依賴的package包/類
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);
	}
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:9,代碼來源:GenericGraphNode.java

示例4: disconnectFollowingNodes

import java.util.Collections; //導入方法依賴的package包/類
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);
	}
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:9,代碼來源:GenericGraphNode.java

示例5: main

import java.util.Collections; //導入方法依賴的package包/類
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);
}
 
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:28,代碼來源:Algorithms1.java

示例6: test

import java.util.Collections; //導入方法依賴的package包/類
@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);

}
 
開發者ID:werewolfKill,項目名稱:werewolf_server,代碼行數:11,代碼來源:ListTest.java

示例7: getDataTypeListCopy

import java.util.Collections; //導入方法依賴的package包/類
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;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:9,代碼來源:DataType.java

示例8: resumeSuggestionOnLastComposedWord

import java.util.Collections; //導入方法依賴的package包/類
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;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:13,代碼來源:WordComposer.java

示例9: main

import java.util.Collections; //導入方法依賴的package包/類
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);
  }
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:47,代碼來源:CopyElementsOfVectorToVectorExample.java

示例10: main

import java.util.Collections; //導入方法依賴的package包/類
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);
  }
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:45,代碼來源:CopyElementsOfVectorToArrayListExample.java

示例11: main

import java.util.Collections; //導入方法依賴的package包/類
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);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:48,代碼來源:CopyElementsOfArrayListToVectorExample.java

示例12: main

import java.util.Collections; //導入方法依賴的package包/類
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);
  }
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:47,代碼來源:CopyElementsOfArrayListToArrayListExample.java

示例13: EpisodeRecyclerAdapter

import java.util.Collections; //導入方法依賴的package包/類
public EpisodeRecyclerAdapter(Context context, List<Episode> episodes, OnItemClickListener itemClickListener) {
    this.context = context;
    this.itemClickListener = itemClickListener;
    list = episodes;
    Collections.copy(list, result);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:7,代碼來源:EpisodeRecyclerAdapter.java

示例14: getDeepCopyOf

import java.util.Collections; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:14,代碼來源:CollectionsUtils.java


注:本文中的java.util.Collections.copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。