List of usage examples for java.util Iterator remove
default void remove()
From source file:Main.java
public static <T extends Collection<?>> void stripNulls(T collection) { Iterator<?> iterator = collection.iterator(); while (iterator.hasNext()) { if (iterator.next() == null) iterator.remove(); }//from w w w .j a v a 2 s. c o m }
From source file:Main.java
public static <T> T removeFrom(Iterable<T> collection, Predicate<T> predicate) { Iterator<T> it = collection.iterator(); while (it.hasNext()) { T o = it.next();//from w w w. j a va 2 s . co m if (predicate.test(o)) { it.remove(); return o; } } return null; }
From source file:Main.java
/** * Makes an intersection betwwen both of the given lists.<br/> * The result contains unique values./*from w ww .j a v a2 s . c om*/ * @param list1 the first list. * @param list2 the second list. * @param <T> * @return the intersection between the two lists. */ public static <T> List<T> intersection(List<T> list1, List<T> list2) { List<T> list = new ArrayList<T>(new LinkedHashSet<T>(list1)); Iterator<T> iterator = list.iterator(); while (iterator.hasNext()) { if (!list2.contains(iterator.next())) { iterator.remove(); } } return list; }
From source file:Main.java
public static void deleteDuplicate(List<Integer> list) { List<Integer> tempList = new ArrayList<Integer>(); Iterator<Integer> iter = list.iterator(); while (iter.hasNext()) { Integer current = iter.next(); if (tempList.contains(current)) { iter.remove(); } else {/*from ww w .j a v a 2s. c om*/ tempList.add(current); } } }
From source file:Main.java
static void jsonObjectClear(JSONObject jsonObject) { @SuppressWarnings("unchecked") Iterator<String> keys = (Iterator<String>) jsonObject.keys(); while (keys.hasNext()) { keys.next();//from w w w. j av a2s . c om keys.remove(); } }
From source file:Main.java
public static void removeNullValues(List<?> list) { Iterator<?> iterator = list.iterator(); while (iterator.hasNext()) { Object value = iterator.next(); if (value == null) { iterator.remove(); }/*from w w w . j a va2s . c o m*/ } }
From source file:Main.java
public static Node SearchNode(NodeList listNode, ArrayList<String> arrStrCompare) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove(); for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { return SearchNode(node.getChildNodes(), arrTempList); }//w ww .ja v a 2 s. co m String strResp = node.getTextContent(); System.out.println("Found DATA [" + strCompare + "]: " + strResp); return node; } } } return null; }
From source file:Main.java
public static String FindNode(NodeList listNode, ArrayList<String> arrStrCompare, String strData) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove(); for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { return FindNode(node.getChildNodes(), arrTempList, strData); }//w w w . j a va 2 s . c om String strResp = node.getTextContent(); System.out.println("Found NODE [" + strCompare + "]: " + strResp); return strResp; } } } return null; }
From source file:manager.NoteManager.java
public static void deleteNoteByIndex(int index) throws IOException { Iterator<Note> itr = modelQueue.iterator(); for (int i = 0; i <= index; i++) itr.next();/*from w w w. j a v a 2 s. c om*/ itr.remove(); saveModels(); }
From source file:Main.java
public static NodeList ChangeNode(NodeList listNode, ArrayList<String> arrStrCompare, String strNewValue) { ArrayList<String> arrTempList = arrStrCompare; Iterator<String> iterator = arrTempList.iterator(); while (iterator.hasNext()) { String strCompare = (String) iterator.next(); iterator.remove(); for (int i = 0; i < listNode.getLength(); i++) { Node node = listNode.item(i); if (strCompare.equals(node.getNodeName())) { if (iterator.hasNext()) { node = ChangeNode(node.getChildNodes(), arrTempList, strNewValue).item(0); break; }//from w w w . j ava 2s . co m node.setTextContent(strNewValue); break; } } } return listNode; }