2013-04-06 48 views
0

访问在地图<类,字符串>变量I具有与类LinkedHashMap中作为关键这样:由Index

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

文件是由3个变量的一类:

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

现在我需要使用索引访问文件中的变量。我知道,LinkedHashMap中不允许使用检索索引值,所以我想这:

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

使用randAccess.get(index)我可以检索密钥本身,而不是特定变量的类中。所以输出结果就像Files @ 6aa91761 = String。

我希望能够得到这个变量,例如:list.Files.status.Get(index)将返回在正确的索引“status”的值。

回答

4

您可以使用.getKey()从Map.Entry中获取文件变量。从那里你可以直接得到状态字段。

randAccess.get(index).getKey().status 
+0

谢谢感谢帮助! – Omid 2013-04-06 19:06:01