Java

1,Map的取值问题,两种方式

Map<String,String[]> data = new HashMap<String,String[]>();
		data.put("price", new String[]{"1","2","3"});
		data.put("type", new String[]{"一","二"});
		
		//一
		Set<Entry<String, String[]>> se = data.entrySet();
		Iterator<Entry<String, String[]>> ie = se.iterator();
		while(ie.hasNext()){
			Entry<String, String[]> ess = ie.next();
			String key = ess.getKey();
			String[] value = ess.getValue();
			for (String string : value) {
				System.out.println(key+","+string);
			}
		}
		
		//二
		Set<String> ks = data.keySet();
		Iterator<String> it = ks.iterator();
		while(it.hasNext()){
			String key = it.next();
			for(int i=0;i<data.get(key).length;i++){
				System.out.println(key+","+data.get(key)[i]);
			}
		}




你可能感兴趣的:(Java)