Java基础知识测试题 - Stream流、多线程和函数式接口
Java基础知识测试题 - Stream流、多线程和函数式接口
题目1 (单选): 下列关于Stream流中获取功能有哪些 ( ) 选项: A. Collection接口中的默认方法stream()生成流 B. Map接口中的默认方法stream()生成流 C. Arrays中的静态方法stream()生成流 D. Stream类中的静态方法stream()生成流
题目2 (单选): 下列关于Stream流中中间功能有哪些 ( ) 选项: A. filter()方法用于对流中的数据进行过滤 B. sorted()方法将流中元素进行排序 C. collector()方法收集流中的数据 D. limit()方法截取指定参数个数的数据
题目3 (单选): 下列关于Stream流中终结功能有哪些 ( ) 选项: A. forEach()方法对流中的元素遍历 B. count()方法返回此流中的元素数 C. skip()方法跳过指定参数个数的数据 D. collector()方法收集流中的数据
题目4 (单选): 观察以下Stream流代码, 最终输出的结果为 ( )
1 public class Test {
2 public static void main(String[] args) {
3 ArrayList<String> list = new ArrayList<>();
4 Collections.addAll(list, "张三丰", "张翠山", "张无忌", "张三", "赵四");
5 long count = list.stream().filter(s -> s.length() == 3).skip(2).count();
6 System.out.println(count);
7 }
8 }
A. 1 B. 2 C. 张翠山 , 张无忌 D. 张无忌
题目5 (单选): 对于以下多线程创建代码补全 ( )
1 public class MyThread01 {
2 public static void main(String[] args) {
3 MyThread mt = new MyThread();
4 // 开启线程
5 __位置3__
6 }
7 }
8 class MyThread __位置1__ Thread {
9 @Override
10 public void __位置2__() {
11 for (int i = 1; i <= 100; i++) {
12 System.out.println("i:" + i);
13 }
14 }
15 }
A. 位置1: extends 位置2: run 位置3: mt.start(); B. 位置1: extends 位置2: run 位置3: mt.run(); C. 位置1: implements 位置2: run 位置3: mt.start(); D. 位置1: implements 位置2: run 位置3: mt.start();
题目6 (单选): 对于以下多线程创建代码补全 ( )
1 public class MyThread02 {
2 public static void main(String[] args) {
3 MyRunnable mr = new MyRunnable();
4 Thread thread= new Thread(__位置3__);
5 thread.start();
6 }
7 }
8
9 class MyRunnable __位置1__ Runnable {
10 @Override
11 public void __位置2__() {
12 for (int i = 1; i <= 100; i++) {
13 System.out.println("i:" + i);
14 }
15 }
16 }
A. 位置1: extends 位置2: run 位置3:mr B. 位置1: extends 位置2: call 位置3:"线程名" C. 位置1: implements 位置2: run 位置3:mr D. 位置1: implements 位置2: run 位置3:"线程名"
题目7 (单选): 关于函数式接口说法正确的是( ) A.函数式接口必须使用@functioninterface注解 B.函数式接口中只能定义一个方法 C.函数式接口中可以定义多个抽象方法 D.函数式接口中只能定义一个抽象方法
题目8 (单选): Stream接口中返回流中元素个数的是( ) A.count() B.size() C.getSize() D.getCount()
题目9 (单选): 能作为Stream接口中的forEach方法的参数的是( ) A.a -> System.out.println(a) B.(a,b) -> a>b C.a -> a>0 D.a -> a!=null
题目10 (单选): String内部实现了什么接口进行比较( ) A.Comparable B.interface C.MyTest D.编译错误
答案:
题目1:A、B、C、D 题目2:A、B、D 题目3:A、B、D 题目4:B 题目5:A 题目6:C 题目7:D 题目8:A 题目9:A 题目10:A
原文地址: https://www.cveoy.top/t/topic/oemG 著作权归作者所有。请勿转载和采集!