Created
January 3, 2016 21:44
-
-
Save herrberk/afda5f4ada66a262099b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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