小编NoI*_*dea的帖子

如何在java中迭代Map?

我需要遍历a BucketMap并获取所有内容,keys但是如何在不buckets[i].next.next.next.key尝试手动操作的情况下进行操作,如我在此处尝试的那样:

public String[] getAllKeys() {

    int j = 0;      //index of string array "allkeys"

    String allkeys[] = new String[8];

    for(int i = 0; i < buckets.length; i++) { //iterates through the bucketmap

        if(buckets[i] != null) {             //checks wether bucket has a key and value
            allkeys[j] = buckets[i].key;     //adds key to allkeys
            j++;                             // counts up the allkeys index after adding key

            if(buckets[i].next != null) {         //checks wether next has a key and value
                allkeys[j] …
Run Code Online (Sandbox Code Playgroud)

java iterator loops initialization hashmap

19
推荐指数
1
解决办法
6万
查看次数

标签 统计

hashmap ×1

initialization ×1

iterator ×1

java ×1

loops ×1