当我遍历我用下面的代码HashMap的名单,我拿到钥匙和值返回列表迭代
System.out.println(" (" + key + "," + value + ")")
但我想我的价值观被返回
重点1 :值1
密钥1:值2
键2:值1
键2:VA鲁2 ...等等。有人可以帮我吗。
public static void main(String[] args) {
Map<String, List<String>> conceptMap = new HashMap<String, List<String>>();
Map<String, List<String>> PropertyMap = new HashMap<String, List<String>>();
try{
Scanner scanner = new Scanner(new FileReader("C:/"));
while (scanner.hasNextLine()){
String nextLine = scanner.nextLine();
String [] column = nextLine.split(":");
if (column[0].equals ("Property")){
if (column.length == 4) {
PropertyMap.put(column [1], Arrays.asList(column[2], column[3]));
}
else {
conceptMap.put (column [1], Arrays.asList (column[2], column[3]));
}
}
}
Set<Entry<String, List<String>>> entries =PropertyMap.entrySet();
Iterator<Entry<String, List<String>>> entryIter = entries.iterator();
System.out.println("The map contains the following associations:");
while (entryIter.hasNext()) {
Map.Entry entry = (Map.Entry)entryIter.next();
Object key = entry.getKey(); // Get the key from the entry.
Object value = entry.getValue(); // Get the value.
System.out.println(" (" + key + "," + value + ")");
}
scanner.close();
}
catch (Exception e) {
e.printStackTrace();
}
Thnak你这么多。有用:) – user1549861 2012-08-02 19:46:53