A hash of hashes
Posted by John_Moylan (jfp), 28 January 2003Morning all.
New to Java, and still trying to figure a few things.
I'm from a Perl background, probably the worst background to come to Java from and tend to build structures similar to the sample below.
I would like to replicate this style in Java, probably using hashTables or the like (though some help with an arrayList of arrayLists wouldn't go amiss too as I use arrays of arrays in Perl, but hear that arrayLists are more flexible)
Or am I approaching this all wrong? perhaps I should discard any Perl'y' thoughts of structures.
sorry for the code formatting, its gone a bit strange.
Posted by admin (Graham Ellis), 28 January 2003There's a rough parallel between Perl's Hashes and HashMaps in Java, and between Perl's lists and ArrayLists in Java.
You'll be setting up your structures using objects, constructors and the like in Java - at first it will seem slow and longwinded but it will get easier with time, and you should find yourself able to maintain the code much more easily once you've put the initial effort in. In other words - though I have given to a comparison don't try to do a straight conversion because Java is different
You could also use a Hashtable in place of a HashMap, and a Vector in place of an ArrayList - in both cases, these alternatives are recommended only if you want Java 1 compatability or you're writing code to be threadsafe. A HashSet is something different - it has keys but no values, and you would use if for the type os situation where, in Perl, you set up a has and just put a "1" into the value to make it true.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho