Last active
May 31, 2016 21:18
-
-
Save TomTasche/3018f32ca54fb06e3f91960c643acb01 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
List<String> data = new LinkedList<String>(); | |
// or if you know the amount of data upfront: | |
List<String> data = new ArrayList<String>(3); | |
data.add("hello"); | |
data.add("hello"); | |
data.add("bye"); | |
System.out.println(data.size()); // 3 | |
// in order to lookup data you always have to iterate the whole list until you find the value you're looking for | |
for (String dataString : data) { | |
if (dataString.equals("bye")) { | |
System.out.println("data found"); | |
} | |
} |
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
Map<String, String> data = new HashMap<String, String>(); | |
data.put("greeting", "hello"); | |
data.put("greeting", "hello"); | |
data.put("farewell", "bye"); | |
System.out.println(data.size()); // 2 | |
// you can look up data efficently using contains | |
if (data.contains("farewell")) { // or: data.get("farewell").equals("bye") | |
System.out.println("data found"); | |
} |
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
Set<String> data = new HashSet<String>(); | |
data.put("hello"); | |
data.put("hello"); | |
data.put("bye"); | |
System.out.println(data.size()); // 2 | |
// you can look up data efficently using contains | |
if (data.contains("bye")) { | |
System.out.println("data found"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment