Here you can find the source of copyAndClearList(List
Parameter | Description |
---|---|
sourceList | List to be copied |
public static List<String> copyAndClearList(List<String> sourceList)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**/*from w w w.ja va 2 s .co m*/ * Copy items from source to target list; then clear source list and set it to null * @param sourceList List to be copied * @return deep copy of list */ public static List<String> copyAndClearList(List<String> sourceList) { ArrayList<String> newList = null; if (sourceList != null) { newList = new ArrayList<String>(); for (int i = 0; i < sourceList.size(); i++) { String oldString = sourceList.set(i, null); String newItem = new String(oldString); oldString = null; newList.add(newItem); } sourceList.clear(); } return newList; } }