查询集合元素所在位置
@Test public void Form_Load() { LinkedHashMap<Integer, Integer> Me = new LinkedHashMap<Integer, Integer>(); Me.put(1, 1); Me.put(2, 2); Me.put(3, 3); Me.put(4, 4); Me.put(5, 5); Me.put(6, 6); for (Map.Entry<Integer, Integer> entry1 : Me.entrySet()) { int a = 0; for (Map.Entry<Integer, Integer> entry : Me.entrySet()) { a = a + 1; if (entry.getKey().equals(entry1.getKey())) { System.out.println(entry1.getKey() + "所在位置:" + a); break; } } } }
1所在位置:1 2所在位置:2 3所在位置:3 4所在位置:4 5所在位置:5 6所在位置:6
本文来自博客园,作者:皮军旗,转载请注明原文链接:https://www.cnblogs.com/pijunqi/p/14656889.html