Search code examples
javadata-structureslinked-listhashmapchaining

What data structure to use?


I need to store the following data;

Clampls = {"23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"}
KJAS3.2 = {"f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"}
...

I was thinking of storing it something like this

 Name        Tokens
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...
Clampls   -> "23e23e" , "ff333g" , "fhgswq" , ... 
KJAS3.2   -> "f34f4f" , "43rf2d" , "3rfas1" , ...  
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...

So sort of like a HashMap. I did some reading in my book Data Structures & Algorithms in Java, R. Lafore and i found what i need which is Separate Chaining / HashChain however they explain it using own built data structure classes.

Is there a "ready made" collection for a HashChain that i can use in java? Something like

Map<String, []String> theMap = new HashMap<String, []String>(); //just an example

Solution

  • Map<String, List<String>> dataStructure = new HashMap<String, List<String>>();
    
    dataStructure.put("Clampls", Arrays.asList("23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"));
    dataStructure.put("KJAS3.2", Arrays.asList("f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"));
    
    dataStructure.put("KJAS3.3", new ArrayList<String>());
    dataStructure.get("KJAS3.3").add("fhgswq");