首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

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

2012-09-23 
哈希表键值怎么放入二维数组?现在有一个哈希表,HashTable ht new HashTable()ht.add(0,111)ht.add(1,22

哈希表键值怎么放入二维数组?
现在有一个哈希表,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++;        }    } 

热点排行