Created
January 11, 2019 16:47
-
-
Save jake-lewis/0fb9022e7002bdabb98b5afc7f3cac74 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collection; | |
import java.util.Arrays; | |
import java.util.Map; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map.Entry; | |
public class Main { | |
public static void main(String[] args) { | |
String[] array = new String[]{"burgers", "fries", "nuggets"}; | |
Collection<String> collection = Arrays.asList("burgers", "fries", "nuggets"); | |
System.out.println("Arrays:"); | |
for(int i = 0; i < array.length; i++) { | |
printString(array[i]); | |
} | |
System.out.println("List loop:"); | |
for (String text: collection) { | |
printString(text); | |
} | |
System.out.println("Stream:"); | |
collection.forEach(s -> printString(s)); | |
System.out.println("Stream & method reference:"); | |
collection.forEach(Main::printString); | |
Map<String, String> combos = new HashMap<>(); | |
combos.put("burgers", "coke"); | |
combos.put("fries", "sprite"); | |
combos.put("nuggets", "tango"); | |
Iterator<Entry<String, String>> iterator = combos.entrySet().iterator(); | |
while(iterator.hasNext()) { | |
Entry<String, String> entry = iterator.next(); | |
if (iterator.next().getValue().equals("tango")) { | |
if(entry.getValue().equals("tango")) { | |
iterator.remove(); | |
} | |
} | |
} | |
} | |
private static void printString(String text) { | |
System.out.println(text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment