So i have the following code which is an array of python dictionaries
userInfo.append({"userType":"blah",
"userFN":"blah",
"userLN": "blah",
"userEmail":"blah@blah.com"})
I want to convert it to Java, right now the way I understand is best is to make a Map, and then create collections for it. Now I did the syntax but I am not sure if that is the best way
Map <String,String> userMap = new HashMap<String,String>();
HashSet<Map<String, String>> userMaps = new HashSet<Map<String,String>>();
...
userMap.put ("userType", "blah");
userMap.put("userFN", "blah");
userMap.put("userLN", "blah");
userMap.put("userEmail", "blah");
userMaps.add(userMap);
Is this the best way to do it?
Note: I haven’t ran this code because I am converting a decent chunk of code and want to convert as much as I can before debugging.
Firstly, if you’re going to use Java, you ought to take advantage of the fact that it’s statically typed. Unless your user object is going to full of arbitrary properties, it’s a good idea to make a class for it.
Also, your
userInfois probably an array, so use an ArrayList instead of a Set.