Created
June 4, 2013 03:46
-
-
Save vaskoz/5703434 to your computer and use it in GitHub Desktop.
Loads a list of Strings into a HashMap. Usage: java HashMapVictim < collisionStrings.txt
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.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class HashMapVictim { | |
final static Object PRESENT = new Object(); | |
public static void main(String[] args) { | |
Map<String, Object> map = new HashMap<String, Object>(); | |
Scanner sc = new Scanner(System.in); | |
String first = null; | |
while (sc.hasNext()) { | |
String key = sc.next(); | |
if (null == first) first = key; | |
// PUTS go at start of chain | |
map.put(key, PRESENT); | |
// THEREFORE, the FIRST is at the END | |
map.get(first); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment