首页 > 编程知识 正文

hashmap循环遍历四种方式,hashmap迭代器遍历并输出

时间:2023-05-05 23:51:26 阅读:30059 作者:225

package com.qst.netty04; import io.netty.buffer.ByteBuf; import io.net ty.buffer.bytebufallocator; import lombok.extern.slf4j.slf4j; import java.util.*; publicclasstestbytebif { hashmap string,Integer map=new HashMapString,Integer (; map.put(zs ),123 ); map.put('ls ',456 ); map.put('ww ',567 ); map.put(ZL ),789; map.put('fs ',891 ); //method (映射); //method _1(映射; //method _2(映射; 方法_3(映射; //map接口的默认方法privatestaticvoidmethod _3(hashmap string,Integer map ) ) map.foreach((key,Value )-) systtysting //以迭代方式创建publicstaticvoidmethod _1(hashmap string,Integer mp ) { SetMap.EntryString,Integer set=mp.entrySet; IteratorMap.EntryString,integer iterator=set.iterator (while (iterator.hasnext () ) { Map.EntryString,integer } system.out.println(next.getkey ()、(next.getvalue )、); 以}//get方式执行publicstaticvoidmethod _2(hashmap string,Integer mp ) { SetString set=mp.keySet; for(strings:set ) integerval=MP.get ); system.out.println(s'----'val ); } publicstaticvoidmethod (hashmap string,Integer mp ) { SetString set=mp.keySet ); for(strings:set ) system.out.println ); } collectionintegervalues=MP.values (; for(integervalue:values ) system.out.println ) value; } }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。