diff --git a/boot-service/src/main/java/com/xwbing/demo/CollectionDemo.java b/boot-service/src/main/java/com/xwbing/demo/CollectionDemo.java index 55b7606..7f5f9ba 100644 --- a/boot-service/src/main/java/com/xwbing/demo/CollectionDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/CollectionDemo.java @@ -8,6 +8,7 @@ import java.util.*; /** * 创建日期: 2017年2月16日 下午4:06:56 * 作者: xiangwb + * 说明: ArrayList初始容量为10,容量不足,会扩充为原有容量的1.5倍+1。然后通过底层的复制方法将原有数据复制过来 */ public class CollectionDemo { diff --git a/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java b/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java index ed7f073..0227bf3 100644 --- a/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java +++ b/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java @@ -13,35 +13,35 @@ import java.util.Set; * 遍历所有的key * 遍历所有的key-value对 * 遍历所有的value(相对不常用) - * - * @author xiangwb + * -------------------------------------------------------------------------------------------------------------------------------- + * 说明: HashMap初始容量capacity为16,加载因子loadFactor为0.75,临界值threshold=capacity*loadFactor,如果元素个数超过临界值,capacity*2 * + * @author xiangwb */ public class ForEachMap { - public static void main(String[] args) { - Map map=new HashMap(); - map.put("语文", 99); - map.put("数学", 98); - map.put("英语", 97); - map.put("物理", 96); - map.put("化学", 99); - System.out.println(map); - - - - /* - * 遍历所有的key + public static void main(String[] args) { + Map map = new HashMap() { + { + put("语文", 99); + put("数学", 98); + put("英语", 97); + put("物理", 96); + put("化学", 99); + } + }; + /* + * 遍历所有的key * set keySet() * 该方法会将当前map中所有的key存入一个set集合后返回 * 那么遍历该集合就等于遍历类所有的key */ - Set keySet=map.keySet(); - for(String key:keySet){ - System.out.println(key); - } - + Set keySet = map.keySet(); + for (String key : keySet) { + System.out.println(key); + } + /* - * 遍历每一组键值对(推荐) + * 遍历每一组键值对(推荐) * map中每一组键值对都是由map的内部类: * java.util.map.entry的一个实例类表示的 * entry有两个方法:getkey getvalue 可以分别获取这一组键值对中的key和value @@ -50,29 +50,27 @@ public class ForEachMap { * 该方法会将map中的每一组键对(entry实例) * 存入一个set集合后返回 */ - Set> entrySet=map.entrySet(); - for(Entry e:entrySet){ - String key=e.getKey(); - Integer value=e.getValue(); - System.out.println(key+":"+value); - } - + Set> entrySet = map.entrySet(); + for (Entry e : entrySet) { + String key = e.getKey(); + Integer value = e.getValue(); + System.out.println(key + ":" + value); + } + /* - * 遍历所有的value + * 遍历所有的value * Collection values() * 该方法会将当前map中所有的value存入一个集合后返回 */ - Collection values=map.values(); - for(Integer value:values){ - System.out.println(value); - } - - - /** - * jdk1.8 - */ - map.forEach((k,v)->{ - System.out.println("key : " + k + "; value : " + v); - }); - } + Collection values = map.values(); + for (Integer value : values) { + System.out.println(value); + } + + + /* + * jdk1.8 + */ + map.forEach((k, v) -> System.out.println("key : " + k + "; value : " + v)); + } } diff --git a/boot-service/src/main/java/com/xwbing/demo/demo.java b/boot-service/src/main/java/com/xwbing/demo/demo.java index 36ea27c..9bb6d5d 100644 --- a/boot-service/src/main/java/com/xwbing/demo/demo.java +++ b/boot-service/src/main/java/com/xwbing/demo/demo.java @@ -2,7 +2,6 @@ package com.xwbing.demo; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; /** @@ -13,20 +12,14 @@ import java.util.concurrent.ExecutionException; */ public class demo { public static void main(String[] args) throws ExecutionException, InterruptedException { + String s="001"; + Integer integer = Integer.valueOf(s); + System.out.println(integer); List list = new ArrayList<>(); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 20; i++) { list.add(i); } - int size = list.size(); - CompletableFuture[] futures = new CompletableFuture[size]; - List finalList = new ArrayList<>(); - for (int i = 0; i < size; i++) { - finalList.add(null); - Integer integer = list.get(i); - int finalI = i; - futures[i] = CompletableFuture.supplyAsync(() -> finalList.set(finalI, integer)); - } - CompletableFuture.allOf(futures).join(); - System.out.println(finalList); + + } }