Java 8中流和集合之间的区别
JavaCollections框架用于存储和处理数据组。它是一个内存中的数据结构,应先计算集合中的每个元素,然后才能将其添加到集合中。
StreamAPI仅用于处理数据组。它不会修改实际的集合,它们仅根据流水线方法提供结果。
Itisusedforstoringandmanipulatinggroupofdata
AlltheclassesandinterfacesofthisAPIisintheJava.utilpackage
Alltheelementsinthecollectionsarecomputedinthebeginning.
Incollections,wecanremoveoraddelements.
Collectionsperformiterationoverthecollection.
集合范例
public class CollectiosExample {
public static void main(String[] args) {
List<String> laptopList = new ArrayList<>();
laptopList.add("HCL");
laptopList.add("Apple");
laptopList.add("Dell");
Comparator<String> com = (String o1, String o2)->o1.compareTo(o2);
Collections.sort(laptopList,com);
for (String name : laptopList) {
System.out.println(name);
}
}
}流示例
public class StreamsExample {
public static void main(String[] args) {
List<String> laptopList = new ArrayList<>();
laptopList.add("HCL");
laptopList.add("Apple");
laptopList.add("Dell");
laptopList.stream().sorted().forEach(System.out::println);
}
}热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短