merge
This commit is contained in:
@@ -51,17 +51,17 @@ public class CollectionDemo {
|
||||
* 那么就不能表示原来的数组了,会抛出UnsupportedOperationException异常
|
||||
*/
|
||||
String[] array = {"one", "two", "three", "four"};
|
||||
List<String> l = Arrays.asList(array);
|
||||
List<String> coll = Arrays.asList(array);
|
||||
/*
|
||||
* 所有的集合提供了一个带有collection类型参数的构造方法 该构造方法称为:复制构造器
|
||||
* 作用是在创建当前集合的同时,集合中包含给定集合中的所有元素
|
||||
*/
|
||||
List<String> list1 = new ArrayList<String>(l);
|
||||
List<String> list1 = new ArrayList<>(coll);
|
||||
|
||||
/**
|
||||
* 集合转数组
|
||||
*/
|
||||
List<String> lsit = new ArrayList<String>(2);
|
||||
List<String> lsit = new ArrayList<>(2);
|
||||
lsit.add("guan");
|
||||
lsit.add("bao");
|
||||
String[] arrayy = new String[lsit.size()];// 大小为list.size()
|
||||
@@ -74,7 +74,7 @@ public class CollectionDemo {
|
||||
/**
|
||||
* 基本api
|
||||
*/
|
||||
List<Integer> list = new ArrayList<Integer>();// 有序
|
||||
List<Integer> list = new ArrayList<>();// 有序
|
||||
list.add(1);
|
||||
list.add(0, 0);// 元素插入到指定位置
|
||||
list.add(2);
|
||||
|
||||
@@ -82,8 +82,7 @@ public class LambdaDemo {
|
||||
reduce = optional.get();
|
||||
}
|
||||
//异步回调
|
||||
// CompletableFuture<List<SysUser>> future = CompletableFuture.supplyAsync(LambdaDemo::getList, taskExecutor);//添加时候可以用任务线程池
|
||||
CompletableFuture<List<JSONObject>> future = CompletableFuture.supplyAsync(LambdaDemo::getList);//查询不需要任务线程池
|
||||
CompletableFuture<List<JSONObject>> future = CompletableFuture.supplyAsync(LambdaDemo::getList);
|
||||
try {
|
||||
List<JSONObject> sysUsers = future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
@@ -103,6 +102,8 @@ public class LambdaDemo {
|
||||
JSONObject object = list.get(i);
|
||||
if (object != null) {
|
||||
futures[i] = CompletableFuture.supplyAsync(() -> finalList.add(setData(object)), taskExecutor);
|
||||
} else {
|
||||
futures[i] = CompletableFuture.runAsync(() -> System.out.println("null"));
|
||||
}
|
||||
}
|
||||
// CompletableFuture.allOf(futures).join();//线程等待,效果等同于get(),不用抛检测异常,不推荐
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.xwbing.demo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -11,24 +12,13 @@ import java.util.LinkedList;
|
||||
*/
|
||||
public class demo {
|
||||
public static void main(String[] args) {
|
||||
|
||||
ArrayList<Integer> objects = new ArrayList<>();
|
||||
long l2 = System.currentTimeMillis();
|
||||
for (int i=0;i<1000000;i++){
|
||||
objects.add(i);
|
||||
}
|
||||
long l3 = System.currentTimeMillis();
|
||||
System.out.println(l3-l2);
|
||||
|
||||
LinkedList<Integer> list = new LinkedList<>();
|
||||
long l = System.currentTimeMillis();
|
||||
for (int i=0;i<1000000;i++){
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
list = list.stream().map(integer -> integer * 10).collect(Collectors.toList());
|
||||
long l1 = System.currentTimeMillis();
|
||||
System.out.println(l1-l);
|
||||
|
||||
|
||||
|
||||
System.out.println(l1 - l);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user