List of usage examples for java.util ArrayList removeAll
public boolean removeAll(Collection<?> c)
From source file:Main.java
public static void main(String[] args) { String givenstring = "this is a test this is a another test"; String[] words = givenstring.split(" "); ArrayList<String> arr = new ArrayList<String>(); for (int i = 0; i < words.length; i++) { arr.add(words[i]);/* ww w . ja v a 2 s. c o m*/ } while (arr.size() != 0) { String word = arr.get(0); int frequency = Collections.frequency(arr, word); arr.removeAll(Collections.singleton(word)); System.out.println(word + frequency); } }
From source file:Main.java
public static void main(String args[]) { ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(1);//from w ww . j a v a2 s . c o m arrlist.add(2); arrlist.add(3); arrlist.add(4); arrlist.add(5); ArrayList<Integer> arrlist2 = new ArrayList<Integer>(); arrlist2.add(1); arrlist2.add(2); arrlist2.add(3); arrlist.removeAll(arrlist2); System.out.println(arrlist); }
From source file:Main.java
/** Returns two ArrayLists, containing the elements only present in the first and second argument, respectively. */ @SuppressWarnings("unchecked") public static ArrayList<String>[] getUniqueElements(Collection<? extends String> list1, Collection<? extends String> list2) { final ArrayList<String> onlyInOne = new ArrayList<String>(list1); onlyInOne.removeAll(list2); Collections.sort(onlyInOne);/*from w w w . j a v a 2s. co m*/ final ArrayList<String> onlyInTwo = new ArrayList<String>(list2); onlyInTwo.removeAll(list1); Collections.sort(onlyInTwo); return new ArrayList[] { onlyInOne, onlyInTwo }; }
From source file:Main.java
private static ArrayList<Integer> getOtherPlatformIds() { Integer[] other = new Integer[PLATFORM_COUNT]; for (int i = 0; i < PLATFORM_COUNT; i++) { other[i] = i;//from w ww.ja v a2s. co m } ArrayList<Integer> range = new ArrayList<Integer>(Arrays.asList(other)); range.removeAll(Arrays.asList(nintendoPlatformIds)); range.removeAll(Arrays.asList(playstationPlatformIds)); range.removeAll(Arrays.asList(xboxPlatformIds)); range.removeAll(Arrays.asList(pcPlatformIds)); return range; }
From source file:Main.java
public static int countDiffElmts(ArrayList<String> u, ArrayList<String> v) { ArrayList<String> listOne = new ArrayList<String>(); ArrayList<String> listTwo = new ArrayList<String>(); listOne.addAll(u);//from w ww.ja va 2 s. co m listOne.retainAll(v); listTwo.addAll(u); listTwo.addAll(v); listTwo.removeAll(listOne); return listTwo.size(); }
From source file:org.openengsb.connector.virtual.filewatcher.internal.FileWatcherConnector.java
private static <ModelType> List<ModelType> subtract(List<ModelType> list1, List<ModelType> list2) { ArrayList<ModelType> result = new ArrayList<ModelType>(list1); result.removeAll(list2); return result; }
From source file:com.sm.test.TestError.java
public static void testSplit() { ArrayList<String> list = new ArrayList<String>(Arrays.asList("1", "2", "3", "4", "5")); ArrayList<String> alist = new ArrayList<String>(Arrays.asList("1", "2", "3")); int j = list.size(); list.removeAll(alist); System.out.println(list.toString() + " alist " + alist); String strToBytes = "strToBytes(\"00005d29e7918b7c9460a4c8496b8640\")"; String[] splits = strToBytes.split("\""); System.out.println(splits[1].getBytes()); }
From source file:org.ebayopensource.turmeric.eclipse.utils.lang.StringUtil.java
/** * Copy non nulls./*from ww w. ja v a 2s .c o m*/ * * @param strings the String... elements to copy if not null * @return non-null String[] of non-null elements from input strings */ public static String[] copyNonNulls(final String... strings) { ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(strings)); arrayList.removeAll(Collections.singleton(null)); return arrayList.toArray(new String[0]); }
From source file:com.redhat.jenkins.nodesharingbackend.ReservationVerifier.java
private static Map<ExecutorJenkins, PlannedFixup> computePlannedFixup(ConfigRepo.Snapshot config, Api api) { // When executor is removed from config repo, it might have ReservationTasks running for a while so it is // necessary to query these executors so the task completion can be detected. Set<ExecutorJenkins> jenkinses = new HashSet<>(config.getJenkinses()); Map<ExecutorJenkins, Map<String, ReservationTask.ReservationExecutable>> trackedReservations = trackedReservations( jenkinses);/*from w w w.j av a 2s.c o m*/ Map<ExecutorJenkins, Set<String>> executorReservations = queryExecutorReservations(jenkinses, api); assert executorReservations.keySet().equals(trackedReservations.keySet()) : executorReservations + " != " + trackedReservations; // TODO verify multiple executors are not using same host // TODO the executor might no longer use the plugin Map<ExecutorJenkins, PlannedFixup> plan = new HashMap<>(); for (Map.Entry<ExecutorJenkins, Set<String>> er : executorReservations.entrySet()) { ExecutorJenkins executor = er.getKey(); @CheckForNull Collection<String> utilizedNodes = er.getValue(); // Might fail getting the data Collection<String> reservedNodes = trackedReservations.get(executor).keySet(); // Failed to query the host - no balancing if (utilizedNodes == null) { if (!reservedNodes.isEmpty()) { LOGGER.warning( "Failed to query executor " + executor.getName() + " with reserved nodes tracked"); } continue; } if (utilizedNodes.equals(reservedNodes)) continue; // In sync ArrayList<String> toSchedule = new ArrayList<>(utilizedNodes); toSchedule.removeAll(reservedNodes); ArrayList<String> toCancel = new ArrayList<>(reservedNodes); toCancel.removeAll(utilizedNodes); plan.put(executor, new PlannedFixup(toCancel, toSchedule)); } return plan; }
From source file:org.openecomp.sdc.ci.tests.utils.Utils.java
public static void compareArrayLists(List<String> actualArraylList, List<String> expectedArrayList, String message) {//from w ww . j a v a 2 s. c o m ArrayList<String> actual = new ArrayList<String>(actualArraylList); ArrayList<String> expected = new ArrayList<String>(expectedArrayList); assertEquals(message + " count got by rest API not match to " + message + " expected count", expected.size(), actual.size()); actual.removeAll(expected); assertEquals(message + " content got by rest API not match to " + message + " expected content", 0, actual.size()); }