Foreach loop in java for Dictionary

后端 未结 4 1108
死守一世寂寞
死守一世寂寞 2021-02-19 20:15

I want to go through every items in a dictionary in java. to clarify what I want to do, this is the C# code

Dictionary LableList = new Dict         


        
4条回答
  •  难免孤独
    2021-02-19 20:29

    I was trying to add the contents of one HashMap (a) into another HashMap (b).

    I found it simple to iterate through HashMap a this way:

    a.forEach((k, v) -> b.put(k, v));
    

    You can manipulate my example to do what ever you want on the other side of "->".

    Note that this is a Lambda expression, and that you would have to use Java 1.8 (Java 8) or later for this to work. :-)

提交回复
热议问题