??Java?б???Map????????
???????????? ???????[ 2017/7/11 9:33:54 ] ??????????????????? Java
????java?е?map?????ж?????????????Iterator????java5????foreach?????java8 Lambda??????????????????????÷??????????????
?????????????map
public class TestMap {
???? public static Map<Integer?? Integer> map = new HashMap<Integer?? Integer>();
????}
????keySet values
???????????map??key????value????map??keySet??values??????????????
???? // KeySet ???key
???? public void testKeySet() {
???? for (Integer key : map.keySet()) {
???? System.out.println(key);
???? }
???? }
???? // values ???value
???? public void testValues() {
???? for (Integer value : map.values()) {
???? System.out.println(value);
???? }
???? }
keySet get(key)
???????????????key??value??????????key??????????map??get(key)???value
????????????????÷?????????????????????
???? // keySet get(key) ???key and value
???? public void testKeySetAndGetKey() {
???? for (Integer key : map.keySet()) {
???? System.out.println(key + ":" + map.get(key));
???? }
???? }
?? entrySet
?????????map entrySet?????????????????key??value?????????£?????????????????????????????????????
???? // entrySet ???key and value
???? public void testEntry() {
???? for (Map.Entry<Integer?? Integer> entry : map.entrySet()) {
???? System.out.println(entry.getKey() + ":" + entry.getValue());
???? }
???? }
???? Iterator
????????????????foreach????????Iterator???棬???foreach??java5?в??????foreach??д?????????????
??????Iterator??????????????foreach????map????????????С?????????????????????????????Iterator??remove??????????
???? // Iterator entrySet ???key and value
???? public void testIterator() {
???? Iterator<Map.Entry<Integer?? Integer>> it = map.entrySet().iterator();
???? while (it.hasNext()) {
???? Map.Entry<Integer?? Integer> entry = it.next();
???? System.out.println(entry.getKey() + ":" + entry.getValue());
???? // it.remove(); ??????
???? }
???? }
????Lambda
????java8????Lambda??????????????????????????????key??value??????????????????????entrySet????????????entrySet????
???? // Lambda ???key and value
???? public void testLambda() {
???? map.forEach((key?? value) -> {
???? System.out.println(key + ":" + value);
???? });
???? }
?????????????
??????10???????????????????????????????????Integer??map?????HashMap
???? static {
???? for (int i = 0; i < 100000; i++) {
???? map.put(i?? 1);
???? }
???? }
?????????????£?
????KeySet?? 392
????Values?? 320
????keySet get(key)?? 552
????entrySet?? 465
????entrySet Iterator??508
????Lambda?? 536
???????????????map?洢???????????map???С?????map??????????????????????????????ò??????????ο?
???????
????????????key??????value????????keySet????values???
????????????key??value??????entrySet
?????????????????????????????????Iterator
??????????????????????????????????????????map????????????????????????????map????????map??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11