中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

網(wǎng)站ftp查詢國際網(wǎng)絡(luò)銷售平臺有哪些

網(wǎng)站ftp查詢,國際網(wǎng)絡(luò)銷售平臺有哪些,網(wǎng)站開發(fā)時如何設(shè)計英文版本,網(wǎng)站域名注冊臺灣一. Stream 1. Stream也叫Stream流,是jdk8開始新增的一套API(java.util.stream.*),可以用于操作集合或者數(shù)組的數(shù)據(jù)。 2. 優(yōu)勢:Stream流大量的結(jié)合了lambda的語言風(fēng)格來編程,提供了一種更加強(qiáng)大,更加簡潔的方式操作集合…

一.?Stream

? ? ? ? 1.?Stream也叫Stream流,是jdk8開始新增的一套API(java.util.stream.*),可以用于操作集合或者數(shù)組的數(shù)據(jù)。

? ? ? ? 2. 優(yōu)勢:Stream流大量的結(jié)合了lambda的語言風(fēng)格來編程,提供了一種更加強(qiáng)大,更加簡潔的方式操作集合或者數(shù)組中的數(shù)據(jù)。

? ? ? ? 3. 使用步驟:

? ? ? ? ? ? ? ? ① 獲取Stream流

? ? ? ? ? ? ? ? ② Stream流常用的中間方法(支持鏈?zhǔn)秸{(diào)用)

? ? ? ? ? ? ? ? ③ Stream 流常見的終結(jié)方法

 public static void main(String[] args) {//StreamList<String> list = new ArrayList<String>();Collections.addAll(list, "卡莎", "卡車", "泰坦", "璐璐", "卡拉", "卡卡卡", "伊澤");System.out.println(list);//[卡莎, 卡車, 泰坦, 璐璐, 卡拉, 卡卡卡, 伊澤]//list中方法 篩選數(shù)據(jù)List<String> list1 = new ArrayList<>();for(String str : list){if (str.contains("卡") && str.length() == 2){list1.add(str);}}System.out.println(list1);//[卡莎, 卡車, 卡拉]//使用stream流 篩選List<String> list2 = list.stream().filter(s -> s.contains("卡")).filter(s -> s.length() == 2).collect(Collectors.toList());System.out.println(list2);//v}

二.?Stream的常用方法

? ? ? ? 1.? 獲取Stream流

方法說明
Collection提供的獲取Stream流default Stream<E> stream()獲取當(dāng)前集合的Stream流
Arrays類提供的獲取Stream流public static <T> Stream<T> stream(T[] array)獲取當(dāng)前數(shù)組的Stream流
Stream提供的獲取Stream流public static<T> Stream<T> of(T... values)獲取當(dāng)前接收數(shù)據(jù)的Stream流
public static void main(String[] args) {//1. 獲取List集合的Stream流List<String> list = new ArrayList<String>();Collections.addAll(list, "卡莎", "卡車", "泰坦", "璐璐", "卡拉", "卡卡卡", "伊澤");//獲取Stream流Stream<String> stream = list.stream();//2. 獲取Set集合的Stream流Set<String> set = new HashSet<String>();Collections.addAll(set, "大宇", "朵朵", "歡歡", "麥琪");//獲取Stream流Stream<String> stream1 = set.stream();stream1.filter(s -> s.contains("歡")).forEach(System.out::println);//3. 獲取Map集合的Stream流Map<String, String> map = new HashMap<>();map.put("楊過", "小龍女");map.put("張無忌", "趙敏");map.put("郭靖", "黃蓉");map.put("令狐沖", "東方不敗");// 獲取Stream流 分開處理Set set2 = map.entrySet();Stream<String> keys = set2.stream();Collection<String> values = map.values();Stream<String> vas = values.stream();//統(tǒng)一處理Set<Map.Entry<String, String>> entry = map.entrySet();Stream<Map.Entry<String, String>> kvs = entry.stream();kvs.filter(k -> k.getKey().contains("張")).forEach(System.out::println);//4. 獲取數(shù)組的Stream流String[] str = {"路馬", "天天", "萊德", "落落"};//public static <T> Stream<T> stream(T[] array)Stream<String> stream2 = Arrays.stream(str);//public static<T> Stream<T> of(T... values)Stream<String> stream3 = Stream.of(str);    
}

? ? ? ? 2. Stream流常見的中間方法

? ? ? ? ? ? ? ? (1) 中間方法是指調(diào)用完成后返回新的Stream流,可以繼續(xù)使用(支持鏈?zhǔn)骄幊?

常用方法說明
Stream<T> filter(Predicate<? super T> predicate)用于對流中的數(shù)據(jù)進(jìn)行過濾
Stream<T> sorted()對元素進(jìn)行升序排序
Stream<T> sorted(Comparator<? super T> comparator)對元素按照指定規(guī)則排序
Stream<T> limit(long maxSize)獲取前幾個元素
Stream<T> skip(long n)跳過前幾個元素
Stream<T> distinct()去除流中重復(fù)的元素
<R> Stream<R> map(Function<? super T, ? extends R> mapper)對元素進(jìn)行加工,并返回對應(yīng)的新流
static <T> Stream<T> concat(Stream a, Stream b)合并a和b兩個流

public class Student{private String name;private int age;private double score;public Student() {}public Student(String name, int age, double score) {this.name = name;this.age = age;this.score = score;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public double getScore() {return score;}public void setScore(double score) {this.score = score;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +", score=" + score +'}';}@Overridepublic boolean equals(Object o) {if (o == null || getClass() != o.getClass()) return false;Student student = (Student) o;return age == student.age && Double.compare(score, student.score) == 0 && Objects.equals(name, student.name);}@Overridepublic int hashCode() {return Objects.hash(name, age, score);}
}
public static void main(String[] args) {List<Double> scores = new ArrayList<Double>();Collections.addAll(scores, 99.0, 96.0, 94.0,59.0, 66.0, 74.0);//成績大于等于60的并排序scores.stream().filter(s -> s >= 60.0).sorted().forEach(System.out::println);//66.0 74.0 94.0 96.0 99.0System.out.println("--------------------------------------------");List<Student> students = new ArrayList<>();Student s1 = new Student("卡莎", 18, 99.0);Student s2 = new Student("泰坦", 19, 93.0);Student s3 = new Student("伊澤", 16, 98.0);Student s4 = new Student("璐璐", 14, 96.0);Student s5 = new Student("璐璐", 14, 96.0);Collections.addAll(students, s1, s2, s3, s4, s5);//找出年齡大于等于16 且小于等于20 按照年齡降序//filter() sorted()students.stream().filter(s -> s.getAge() >= 16 && s.getAge() <= 20).sorted(((o1, o2) -> o2.getAge() - o1.getAge())).forEach(System.out::println);System.out.println("--------------------------------------------");//找出分?jǐn)?shù)最高的前三名// sorted() limit()students.stream().sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).limit(3).forEach(System.out::println);System.out.println("--------------------------------------------");//找出分?jǐn)?shù)最低的 倒數(shù)3名//sorted() skip()students.stream().sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).skip(students.size() - 3).forEach(System.out::println);System.out.println("--------------------------------------------");//成績大于等于95的 去除重復(fù)的名字// distinct() 自定義類型 如果希望內(nèi)容一樣認(rèn)為重復(fù) 需重寫 equals()和 hashCode()//filter() map()  distinct()students.stream().filter(s -> s.getScore() >= 95).map(s -> s.getName()).distinct().forEach(System.out::println);students.stream().filter(s -> s.getScore() >= 95).distinct().forEach(System.out::println);//static <T> Stream<T> concat(Stream a, Stream b)	合并a和b兩個流Stream<String> stream = Stream.of("1", "2", "3");Stream<String> stream2 = Stream.of("4", "5", "6", "7", "8", "9");Stream<String> stream3 = Stream.concat(stream, stream2);stream3.forEach(System.out::println);}

? ? ? ? 3. Stream流常見的終結(jié)方法

? ? ? ? ? ? ? ? (1)?終結(jié)方法指的是調(diào)用完成后,不會再返回新的Stream流了,不能再繼續(xù)使用Stream流了。

方法名稱說明
void forEach(Consumer action)對此流運(yùn)算后的元素進(jìn)行遍歷
long count()統(tǒng)計此流運(yùn)算后的元素個數(shù)
Optional<T> max(Comparator<? super T> copmarator)獲取此流運(yùn)算后的最大值元素
Optional<T> min(Comparator<? super T> copmarator)獲取此流運(yùn)算后的最小值元素
方法名稱說明
R collect(Collector collector)把流處理后的結(jié)果放到一個指定的集合中
Object[] toArray()把流處理后的結(jié)果放到一個指定的數(shù)組中
public static void main(String[] args) {List<Student> students = new ArrayList<>();Student s1 = new Student("卡莎", 18, 99.0);Student s2 = new Student("泰坦", 19, 93.0);Student s3 = new Student("伊澤", 16, 98.0);Student s4 = new Student("璐璐", 14, 96.0);Student s5 = new Student("璐璐", 14, 96.0);Collections.addAll(students, s1, s2, s3, s4, s5);// 計算分?jǐn)?shù)超過95的有幾個 .count()long l = students.stream().filter(s -> s.getScore() > 95).count();System.out.println(l);//4//找出分?jǐn)?shù)最高的 并輸出 .max()Student smax = students.stream().max((o1, o2) -> Double.compare(o1.getScore(), o2.getScore())).get();System.out.println(smax);//找出分?jǐn)?shù)最低的 并輸出 .min()Student smin = students.stream().min((o1, o2) -> Double.compare(o1.getScore(), o2.getScore())).get();System.out.println(smin);//計算分?jǐn)?shù)超過95的 并放到一個新集合中//流只能收集一次List<Student> list1 = students.stream().filter(s -> s.getScore() > 95).collect(Collectors.toList());System.out.println(list1);Set<Student> list2 = students.stream().filter(s -> s.getScore() > 95).collect(Collectors.toSet());System.out.println(list2);//找出分?jǐn)?shù)超過95的 并把名字和分?jǐn)?shù)放到一個map集合中//不會自動去重 需調(diào)用distinct()去重Map<String, Double> map = students.stream().filter(s -> s.getScore() > 95).distinct().collect(Collectors.toMap(m -> m.getName(), m -> m.getScore()));System.out.println(map);//找出分?jǐn)?shù)超過95的 并把名字和分?jǐn)?shù)放到一個數(shù)組Object[] arr = students.stream().filter(s -> s.getScore() > 95).toArray();Student[] arr1 = students.stream().filter(s -> s.getScore() > 95).toArray(len -> new Student[len]);System.out.println(Arrays.toString(arr));System.out.println(Arrays.toString(arr1));
}

http://www.risenshineclean.com/news/30449.html

相關(guān)文章:

  • 西安做網(wǎng)站建設(shè)的qq推廣工具
  • 醫(yī)藥網(wǎng)站建設(shè)蟻坊軟件輿情監(jiān)測系統(tǒng)
  • 山西做網(wǎng)站運(yùn)營的公司網(wǎng)店運(yùn)營培訓(xùn)哪里好
  • 視差效果網(wǎng)站網(wǎng)絡(luò)推廣是什么職業(yè)
  • 公司請做網(wǎng)站百度 競價排名
  • 怎么找人做動漫視頻網(wǎng)站seo關(guān)鍵詞排名優(yōu)化的方法
  • 找人做網(wǎng)站去哪里找黃岡網(wǎng)站推廣廠家
  • 商城網(wǎng)站建設(shè)運(yùn)營合同天津優(yōu)化公司哪家好
  • 門戶網(wǎng)站建設(shè)ppt方案seo公司費(fèi)用
  • 工作室怎么網(wǎng)站備案外貿(mào)網(wǎng)站推廣平臺有哪些
  • 鄭州高新區(qū)做網(wǎng)站開發(fā)的公司網(wǎng)站seo推廣排名
  • 電子商務(wù)網(wǎng)站建設(shè)總結(jié)免費(fèi)網(wǎng)站在線觀看人數(shù)在哪直播
  • 網(wǎng)站地圖對seo的影響品牌營銷策劃與管理
  • 做pc端網(wǎng)站平臺今日頭條熱點(diǎn)新聞
  • 建筑網(wǎng)片的用途seo優(yōu)化工具
  • 沌口網(wǎng)站建設(shè)淘寶seo搜索排名優(yōu)化
  • wordpress主頁底端添加圖常州網(wǎng)站seo
  • 公司網(wǎng)站可以自己做河南關(guān)鍵詞排名顧問
  • 網(wǎng)站建設(shè)文案有趣網(wǎng)站關(guān)鍵詞快速排名服務(wù)
  • 網(wǎng)站備案最快多久seo學(xué)院培訓(xùn)班
  • 上傳網(wǎng)站怎么安裝寧德市蕉城區(qū)疫情
  • wordpress隱藏回復(fù)插件seo做關(guān)鍵詞怎么收費(fèi)的
  • 網(wǎng)站發(fā)外鏈中山seo排名
  • 四川移動網(wǎng)站建設(shè)怎樣做推廣是免費(fèi)的
  • 網(wǎng)頁界面設(shè)計系統(tǒng)seo描述是什么
  • 網(wǎng)頁設(shè)計軟件adobe鄭州seo技術(shù)顧問
  • ui設(shè)計培訓(xùn)需要多少費(fèi)用百度關(guān)鍵詞搜索優(yōu)化
  • 織夢網(wǎng)站動態(tài)網(wǎng)站建設(shè)推廣優(yōu)化
  • 老鷹畫室網(wǎng)站哪家做的b站視頻怎么快速推廣
  • 建網(wǎng)站怎么分類亞馬遜關(guān)鍵詞搜索器