[英]how to get values from an ArrayList<Hashtable<String, ArrayList<String>>>
I have a function that is capable to read data from multiple files with the following structure: 我有一个能够从多个文件读取数据的函数具有以下结构:
id date temp psal
1 2016/02/01 37.6 35.9
2 2016/02/02 30.3 35.7
3 2016/02/03 28.2 36.8
4 2016/02/04 27.7 37.7
5 2016/02/05 28.7 37.9
6 2016/02/06 28.7 37.9
The function is: 功能是:
ArrayList<Hashtable<String, ArrayList<String>>> processedFilesArray = ReadFiles(files);
If I try to retrieve the data by using for example: 如果我尝试使用例如检索数据:
System.out.println(processedFilesArray.get(0));
Then I get the following response: 然后我得到以下回复:
{Psals=[35.9, 35.7, 36.8, 37.7, 37.9, 37.9], Temps=[37.6, 30.3, 28.2, 27.7, 28.7, 28.7], ids=[1, 2, 3, 4, 5, 6], DateStrings=[2016/02/01, 2016/02/02, 2016/02/03, 2016/02/04, 2016/02/05, 2016/02/06]}
My question is: How can I obtain the different values of the keys (Temps, Psals, ids, etc) by sepparate to plot them using jfreechart? 我的问题是:如何通过sepparate使用jfreechart绘制它们来获取键的不同值(Temps,Psals,id等)?
Thanks in advance 提前致谢
You can obtain the keys and values by this way: 您可以通过以下方式获取键和值:
//Each hastTable of proccesedFilesArray
for(Hashtable<String,ArrayList<String>> processedFile : processedFilesArray){
//Each entrySet of proccesedFile
for(Entry<String, ArrayList<String>> entry : processedFile.entrySet()){
//Filter here by key or value with if conditions
String key = entry.getKey();
ArrayList<String> listValue = entry.getValue();//List of Strings
for(String value : listValue){
//each value per hashtable key
}
}
}
I dont really know how do you want to work with this but that could be a way to iterate your list and get the values of each record. 我真的不知道你想如何使用它,但这可能是一种迭代列表并获取每条记录值的方法。
You can get list of keys in your Hashtable by method keySet() , which return Set of Keys. 您可以通过方法keySet()获取Hashtable中的键列表,该键返回Set of Keys。
You can convert Set to Array list like this :- 您可以将Set转换为Array列表,如下所示: -
ArrayList keyList = new ArrayList(processedFilesArray.get(0).keySet()); ArrayList keyList = new ArrayList(processedFilesArray.get(0).keySet());
More about keySet http://www.tutorialspoint.com/java/util/hashmap_keyset.htm 有关keySet的更多信息, 请访问http://www.tutorialspoint.com/java/util/hashmap_keyset.htm
I finally solved this issue following Hitesh response, by using: 我终于通过使用以下方法解决了Hitesh响应后的问题:
ArrayList keyList = new ArrayList(processedFilesArray.get(1).values());
System.out.println(keyList.get(0));
This returns me the first group (Psals) from the second file read: 这将返回第二个文件读取的第一组(Psals):
[35.9, 35.7, 36.8, 37.7, 37.9, 37.9]
Thank you guys for your help!! 谢谢你们的帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.