Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created June 4, 2013 03:46
Show Gist options
  • Save vaskoz/5703434 to your computer and use it in GitHub Desktop.
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
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