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

javalinkedhashmap迭代

java linkedhashmap iteration(javalinkedhashmap迭代)
本文介紹了javalinkedhashmap迭代的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有兩個哈希圖

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

每個 hashmap 都有不同的鍵和值.我正在嘗試遍歷兩個哈希圖同時將 val1->int[] 的每個值乘以 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

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

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

謝謝

推薦答案

你可能做錯了...

首先,HashMap 不能存儲整數(shù),它需要適當?shù)膶ο蟆热?Integer–數(shù)組是一個對象,盡管它隱藏在一些語法糖后面.

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)遍歷兩張地圖,如果它們碰巧有相同的大小,我想你是這個意思.

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);
    }

但您可能應該回過頭來重新考慮如何存儲數(shù)據(jù) –你為什么要使用地圖,關鍵是什么?

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

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

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

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(liá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(將對象列表轉(zhuǎn)換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應一個HashSet創(chuàng)建一個HashMap.出發(fā)點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
Best way to order an HashMap by key in Java?(在 Java 中按鍵排序 HashMap 的最佳方法?)
主站蜘蛛池模板: 一区在线观看 | 伊人网在线视频 | 色婷婷基地| 超碰人人艹| 久久久久久久久久国产 | 国产成人在线免费视频 | 中文字幕www | 久久久久人 | 日批视频免费在线观看 | 青草视频在线 | 在线免费观看黄色片 | 黄色www. | 国产精品第一 | 蜜桃精品噜噜噜成人av | 欧美成人一区二区 | 日韩精品在线一区二区 | 国产精品成人免费视频 | 欧美成人精品一区二区三区在线看 | 国产精品福利在线 | 涩五月婷婷| 亚洲激情视频 | 免费中文字幕日韩欧美 | 中文字幕2021 | 在线国产视频 | 国产精品手机在线 | 午夜精品福利视频 | 亚洲国产成人精品女人久久久 | 91视频精选 | 久久久一区二区三区 | 亚洲在线一区 | 伊人国产女| 午夜视频在线播放 | 糖心vlog精品一区二区 | 亚洲视频在线看 | 国产欧美日韩视频 | 福利在线观看 | 久草网在线 | 色婷婷免费视频 | 美女天天干 | 日韩精品福利 | av一二三区 |