Reputation: 29
i have tried this:
public static void main(String[] args) {
String[] common = {"hello", "there", "hi"};
ArrayList<String> list = new ArrayList<>();
LinkedList<ArrayList<String>> las = new LinkedList<>();
list.add("how");
list.add("there");
las.add(list);
for (int i = 0; i < las.size(); i++) {
String[] tStringArray = null;
Object[] tObject = las.get(i).toArray();
String[] tString = Arrays.copyOf(tObject, tObject.length, String[].class);
for (int j = 0; j < tString.length; j++) {
for (int k = 0; k < common.length; k++) {
if (tString[j] == common[k]) {
tStringArray = (String[]) ArrayUtils.removeElement(tString, common[k]);
}
}
}
ArrayList<String> tList = new ArrayList<>(Arrays.asList(tStringArray));
las.set(i, tList);
}
}
i have used commons lang library. i have String array of commons {"hello", "there", "hi"} and i have Linked list in form of LinkedList(ArrayList(String)) and i added some element to Linked List and now i want to remove all words from commons from Linked List. How can i do that? please help..
Upvotes: 0
Views: 59
Reputation: 11739
If you need to remove all common words you can use List.removeAll
method:
list.removeAll(Arrays.asList(common));
Upvotes: 1