久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

javalinkedhashmap迭代

java linkedhashmap iteration(javalinkedhashmap迭代)
本文介紹了javalinkedhashmap迭代的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有兩個(gè)哈希圖

LinkedHashMap<String, int[]> val1 = new LinkedHashMap<String, int[]>();
LinkedHashMap<String, int> val2 = new LinkedHashMap<String, int>();

每個(gè) hashmap 都有不同的鍵和值.我正在嘗試遍歷兩個(gè)哈希圖同時(shí)將 val1->int[] 的每個(gè)值乘以 val2->int

each hashmap has different key and values. I am trying to iterate over both hashmap at the same time and multiply each value of val1->int[] to val2->int

最簡(jiǎn)單快捷的方法是什么?我在兩個(gè)哈希圖中都有數(shù)千個(gè)值.

What is the easiest and fasted way to do it? I have thousands values in both hashmap.

謝謝

推薦答案

你可能做錯(cuò)了...

首先,HashMap 不能存儲(chǔ)整數(shù),它需要適當(dāng)?shù)膶?duì)象——比如 Integer–數(shù)組是一個(gè)對(duì)象,盡管它隱藏在一些語(yǔ)法糖后面.

First, a HashMap can't store ints, it needs proper objects - like Integer – An array is an object, although it's hidden behind some syntactic sugar.

下面是如何循環(huán)遍歷兩張地圖,如果它們碰巧有相同的大小,我想你是這個(gè)意思.

Here's how to loop over both maps, if they happens to have the same size, which is what I think you mean.

    Iterator<int[]> expenses = val1.values().iterator();
    Iterator<Integer> people = val2.values().iterator();

    assert val1.size() == val2.size() : " size mismatch";
    while (expenses.hasNext()) {
        int[] expensesPerMonth = expenses.next();
        int persons = people.next();

        // do strange calculation
        int strangeSum = 0;
        for (int idx = 0; idx < expensesPerMonth.length; idx++) {
            strangeSum += persons * expensesPerMonth[idx];
        }
        System.out.println("strange sum :" + strangeSum);
    }

但您可能應(yīng)該回過(guò)頭來(lái)重新考慮如何存儲(chǔ)數(shù)據(jù) –你為什么要使用地圖,關(guān)鍵是什么?

But You should probably go back and rethink how you store your data – why are you using maps, and whats the key?

例如,創(chuàng)建一個(gè)代表每月支出和人數(shù)組合的對(duì)象不是更好嗎?

Wouldn't it be better to create an object that represents the combination of monthly expenses and number of people, for instance?

這篇關(guān)于javalinkedhashmap迭代的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉(zhuǎn)換為 Map)
Getting data from JSON(從 JSON 獲取數(shù)據(jù))
Converting a list of objects to Map(將對(duì)象列表轉(zhuǎn)換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個(gè)固定的Key對(duì)應(yīng)一個(gè)HashSet創(chuàng)建一個(gè)HashMap.出發(fā)點(diǎn))
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無(wú)法寫入請(qǐng)求:找不到合適的 HttpMessageConverter) - IT屋-程序員
Best way to order an HashMap by key in Java?(在 Java 中按鍵排序 HashMap 的最佳方法?)
主站蜘蛛池模板: 亚洲精品白浆高清久久久久久 | 在线精品亚洲欧美日韩国产 | 91精品久久久久久久久中文字幕 | 91极品尤物在线播放国产 | 久久99精品久久久久 | 国产免费观看久久黄av片涩av | 欧美日韩一区二区三区四区 | 亚洲综合五月天婷婷 | 毛片区| 欧美成人一区二区 | www.久久99 | 国产视频一区二区 | 精品国产欧美一区二区 | 国产黄色一级片 | 91综合网 | 亚洲精品免费观看 | 欧美日本一区 | 综合久久综合久久 | 成人在线观看免费视频 | 少妇精品亚洲一区二区成人 | 亚洲一区中文字幕 | 亚洲久久一区 | 99久久久久 | 大象视频一区二区 | 久久久.com | 中文字幕一级 | 午夜激情视频在线 | 久久久爽爽爽美女图片 | 羞羞视频在线免费 | 盗摄精品av一区二区三区 | 亚洲视频中文字幕 | 女同久久另类99精品国产 | 成人性视频在线播放 | www.天天操.com | 精品久久久久久久久久久 | 中文字幕一区在线 | 91亚洲国产成人久久精品网站 | 久久不卡 | 一级黄在线观看 | 丁香五月网久久综合 | 97超碰人人 |