Best way to convert strings to symbols in hash

What’s the (fastest/cleanest/straightforward) way to convert all keys in a hash from strings to symbols in Ruby? This would be handy when parsing YAML. my_hash = YAML.load_file(‘yml’) I’d like to be able to use: my_hash[:key] Rather than: my_hash[‘key’] 31 Answers 31 Here’s a better method, if you’re using Rails: params.symbolize_keys The end. If you’re not, … Read more

What happens when a duplicate key is put into a HashMap?

If I pass the same key multiple times to HashMap’s put method, what happens to the original value? And what if even the value repeats? I didn’t find any documentation on this. Case 1: Overwritten values for a key Map mymap = new HashMap(); mymap.put(“1″,”one”); mymap.put(“1″,”not one”); mymap.put(“1″,”surely not one”); System.out.println(mymap.get(“1”)); We get surely not … Read more

java.lang.OutOfMemoryError: GC overhead limit exceeded [duplicate]

This question already has answers here: Error java.lang.OutOfMemoryError: GC overhead limit exceeded (22 answers) Closed 2 years ago. I am getting this error in a program that creates several (hundreds of thousands) HashMap objects with a few (15-20) text entries each. These Strings have all to be collected (without breaking up into smaller amounts) before … Read more