0

I have a LinkedHashMap with a class as the Key as such:

private final Map<Files, String> list = new LinkedHashMap<Files,String>();

Files is a class consisting of 3 variables:

class Files {
public String file;
public String duration;
public String status;
}

Now I need to access the variables in Files using a index. I know that LinkedHashMap does not allow retrieving values using Index, so I tried this:

List<Entry<Files,String>> randAccess = new ArrayList<Entry<Files,String>>(list.entrySet());

Using randAccess.get(index) I can retrieve the Key itself, but not the specific variables inside the class. So the output is somethinglike Files@6aa91761=String.

I want to be able to get the variable, something like: list.Files.status.Get(index) would return return the value of "status" at the right Index.

Omid
  • 823
  • 1
  • 11
  • 31

1 Answers1

4

You can get the Files variables from the Map.Entry using .getKey(). From there you can get the status field directly.

randAccess.get(index).getKey().status
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005