当前位置: 代码迷 >> J2SE >> 哈希表键值如何放入二维数组
  详细解决方案

哈希表键值如何放入二维数组

热度:9801   发布时间:2013-02-25 00:00:00.0
哈希表键值怎么放入二维数组?
现在有一个哈希表,HashTable ht = new HashTable();
  ht.add(0,111);
  ht.add(1,222);
  ht.add(2,333);
怎么将ht的键值存放到一个二维数组中,高分求具体实现!!!

------解决方案--------------------------------------------------------
说实话 没有搞明白 你想怎么做

你这个二维数组 要是个什么格式呢?

hashtable 里 0=111 1=222 2=333
二维组里怎么放
 0 1 2
 111 222 333


------解决方案--------------------------------------------------------
试一试下面的代码,自己运行可以,不知是不是你要表达的意思
Java code
import java.util.HashMap;public class TestHash {    /**     * @param args     */    public static void main(String[] args) {        HashMap<Integer[][],String> hashMap = new HashMap<Integer[][], String>();        Integer [][] aIntegers = new Integer[3][2];        aIntegers[1][1] = 1;        hashMap.put(aIntegers, "abc");        String string = hashMap.get(aIntegers);        System.out.println(string);    }}
------解决方案--------------------------------------------------------
太感谢了,正是额要找的code,嘻嘻
探讨

试一试下面的代码,自己运行可以,不知是不是你要表达的意思
Java code

import java.util.HashMap;

public class TestHash {

/**
* @param args
*/
public static void main(String[] args) {

HashMap<Integer[……

------解决方案--------------------------------------------------------
對應著放不就得了,有什麽問題嗎?
------解决方案--------------------------------------------------------
Java code
public static void main(String[] args) {        Hashtable<Integer,Integer> ht = new Hashtable<Integer,Integer>();        ht.put(0,111);        ht.put(1,222);        ht.put(2,333);        Integer [][] Integers = new Integer[3][2];        Set<Entry<Integer, Integer>> hs = ht.entrySet();        int i= 0;        for(Entry<Integer, Integer> e:hs){            int j = 0;            Integers[i][j++]=e.getKey();            Integers[i][j++]=e.getValue();            i++;        }    }
  相关解决方案