把一个HashMap的值全部取出来,放到两个数组中

先是从数据库中获取所有的值,返回一个HashMap类型的数据:
<pre name="code" class="java">	private HashMap<String, String> searchSql() {
		int columnsSize = cursor.getColumnCount();
		HashMap<String, String> map = new HashMap<String, String>();
		if (cursor != null) {
			while (cursor.moveToNext()) {
				System.out.println("设备名称ID " + cursor.getString(1)
						+ "<--------->" + cursor.getString(0));
				for (int i = 0; i < columnsSize; i++) {
					map.put(cursor.getString(1), cursor.getString(0));
				}
			}
		}
		return map;
	}



然后保存包
<pre name="code" class="java">		HashMap<String, String> map =searchSql();//返回的map
		List<String> keyList = new ArrayList<String>(map.keySet());
		List<String> valueList = new ArrayList<String>(map.values());
		for(int i = 0; i < map.size(); i++){
			System.out.println("测试 " + valueList.get(i));
			tableView.addBasicItem(new BasicItem(keyList.get(i),valueList.get(i) , false));//用的UItable开源控件,显示在listview中
		}




原文地址:https://www.cnblogs.com/sowhat4999/p/4439853.html