Skip to content

Instantly share code, notes, and snippets.

@herrberk
Created January 3, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrberk/afda5f4ada66a262099b to your computer and use it in GitHub Desktop.
Save herrberk/afda5f4ada66a262099b to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public class UsefulCodes {
// ArrayLists
public static List<String> listeler(int a){
String[] words2={"eggs","lazers","hats","pie"};
String[] words3={"lazers","hats"};
List<String> list = new ArrayList<>();
List<String> list2 = new ArrayList<>();
//add array items to the list
for(String x: words2)
list.add(x);
for(String y: words3)
list2.add(y);
if(a==1)return list;
else return list2;
}
//editList
public static void editList(Collection<String> l1, Collection<String> l2){
Iterator<String> it = l1.iterator();
while(it.hasNext()){
if(l2.contains(it.next()))
it.remove();
}
System.out.println(l1.toString());
}
// Main Method
public static void main(String[] args) {
// Compares 2 lists and excludes the identical elements //from the first list
editList(listeler(1),listeler(2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment