黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

Java8新特性
Java9新特性

Java8中HashMap的性能提升與Stream在開發(fā)中的應(yīng)用

Stream在開發(fā)中的應(yīng)用

package com.wkcto.stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;

/**
 * Author : 動(dòng)力節(jié)點(diǎn)老崔
 */
public class Test03 {
    public static void main(String[] args) {
        //把Car小汽車的數(shù)據(jù)保存到List集合中
        List<Car> carshop = new ArrayList<>();
        carshop.add(new Car("Benz", false, 68, CarType.SUV));
        carshop.add(new Car("Audi", true, 28, CarType.HATCHBACK));
        carshop.add(new Car("BMW", false, 88, CarType.HATCHBACK));
        carshop.add(new Car("Geeley", true, 18, CarType.HATCHBACK));
        carshop.add(new Car("Xiali", true, 8, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Haval", false, 18, CarType.SUV));
        carshop.add(new Car("Jeep", true, 38, CarType.SUV));
        carshop.add(new Car("Honda", false, 28, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Chery", true, 18, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Benz", false, 58, CarType.THREECOMPARTMENT));

        //1根據(jù)價(jià)格降序排序后,顯示汽車品牌
        carshop.stream()
                .sorted((c1,c2) -> c2.getPrice()-c1.getPrice())
                .map(Car::getBrand)
                .distinct()
                .forEach(System.out::println);
        System.out.println("---------------------");

        //2 找出已賣的車, 按價(jià)格升序排序
        carshop.stream()
                .filter(car -> car.isSold() )
                .sorted(Comparator.comparing(Car::getPrice))
                .forEach(System.out::println);
        System.out.println("---------------------");

        //3 查看有哪些車型
        carshop.stream()
                .map(car -> car.getType())
                .distinct()
                .forEach(System.out::println);
        System.out.println("---------------------");

        //4SUV型號的車有哪些
        List<Car> collect = carshop.stream()
                .filter(car -> car.getType() == CarType.SUV)
                .collect(Collectors.toList());
        System.out.println( collect );

        // 40萬以下的車的品牌, 排序
        carshop.stream()
                .filter(car -> car.getPrice() < 40)
                .map(Car::getBrand)
                .distinct()
                .sorted()
                .forEach(System.out::println);
        System.out.println("---------------------");

        //6)統(tǒng)計(jì)沒有賣出去的車的數(shù)量
        System.out.println( carshop.stream().filter(car -> !car.isSold()).count() );

        //7)判斷是否有Geeley品牌的汽車
        System.out.println( carshop.stream().anyMatch(car -> "Geeley".equals(car.getBrand())));

        //8)最貴的車的價(jià)格
        System.out.println(carshop.stream().map(Car::getPrice).reduce(Integer::max).get() );

        //9)顯示已賣出去最貴的車
        System.out.println( carshop.stream().filter(Car::isSold)
//            .reduce(BinaryOperator.maxBy((car1, car2)->(car1.getPrice()- car2.getPrice())))
               .collect(Collectors.maxBy(Comparator.comparing(Car::getPrice)))
                .get()
        );
    }
}
package com.wkcto.stream;

import java.util.Objects;

/**
 * Author : 動(dòng)力節(jié)點(diǎn)老崔
 */
public class Car {
    private String brand;   //品牌
    private  boolean sold;  //是否已賣
    private int price;
    private CarType type;   //車型

    public Car(String brand, boolean sold, int price, CarType type) {
        this.brand = brand;
        this.sold = sold;
        this.price = price;
        this.type = type;
    }

    public Car() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return sold == car.sold &&
                price == car.price &&
                Objects.equals(brand, car.brand) &&
                type == car.type;
    }

    @Override
    public int hashCode() {
        return Objects.hash(brand, sold, price, type);
    }

    @Override
    public String toString() {
        return "Car{" +
                "brand='" + brand + '\'' +
                ", sold=" + sold +
                ", price=" + price +
                ", type=" + type +
                '}';
    }

    public String getBrand() {
        return brand;
    }

    public Car setBrand(String brand) {
        this.brand = brand;
        return this;
    }

    public boolean isSold() {
        return sold;
    }

    public Car setSold(boolean sold) {
        this.sold = sold;
        return this;
    }

    public int getPrice() {
        return price;
    }

    public Car setPrice(int price) {
        this.price = price;
        return this;
    }

    public CarType getType() {
        return type;
    }

    public Car setType(CarType type) {
        this.type = type;
        return this;
    }
}
package com.wkcto.stream;

/**
 * Author : 動(dòng)力節(jié)點(diǎn)老崔
 */
public enum CarType {
    HATCHBACK, THREECOMPARTMENT,SUV
}

對HashMap性能的提升

全部教程
主站蜘蛛池模板: 国产黄色精品 | 最近免费中文字幕大全免费 | 精品一区二区三区视频在线观看 | 狠狠乱| 国产一级黄色网 | 一级毛片免费完整视频 | 成人免费a视频 | 欧美乱大交xxxx| 色片免费网站 | 国产 在线 | 日韩 | 亚洲系列中文字幕一区二区 | 日本一区二区免费看 | 国产精品视频二区不卡 | 朝鲜free嫩白的18sex性 | 欧美日本综合 | 天天精品视频在线观看资源 | 黄色免费网站视频 | 水果视频在线观看 | 色多多污网站 | 天天摸夜夜添夜夜添国产 | 免费在线不卡视频 | 亚洲人成网站在线观看播放动漫 | 香蕉在线精品亚洲第一区 | 色哒哒影院 | 女人洗澡一级毛片一级毛片 | 国产日韩欧美视频 | 天天舔天天操天天干 | 日韩中文字幕a | 国产成人免费影片在线观看 | 日本国产一区在线观看 | 欧洲最暴性xxxⅹ | 清风阁我爱干视频 | 天堂中文www在线 | 老扒夜夜春宵粗大好爽aa毛片 | 国内精品久久久久影 | 波多野结衣一级视频 | 久久久婷婷 | 天天操天天草 | 中文字幕看片在线a免费 | 亚洲欧美日韩在线一区二区三区 | 免费网站看v片在线成人国产系列 |