大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

Java8新特性
Java9新特性

Java8中HashMap的性能提升與Stream在開發中的應用

Stream在開發中的應用

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 : 動力節點老崔
 */
public class Test03 {
    public static void main(String[] args) {
        //把Car小汽車的數據保存到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根據價格降序排序后,顯示汽車品牌
        carshop.stream()
                .sorted((c1,c2) -> c2.getPrice()-c1.getPrice())
                .map(Car::getBrand)
                .distinct()
                .forEach(System.out::println);
        System.out.println("---------------------");

        //2 找出已賣的車, 按價格升序排序
        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)統計沒有賣出去的車的數量
        System.out.println( carshop.stream().filter(car -> !car.isSold()).count() );

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

        //8)最貴的車的價格
        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 : 動力節點老崔
 */
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 : 動力節點老崔
 */
public enum CarType {
    HATCHBACK, THREECOMPARTMENT,SUV
}

對HashMap性能的提升

全部教程
主站蜘蛛池模板: 天天干天天摸 | 26uuu久久| 麻豆精品在线 | 色香欲综合成人免费视频 | 成人二区 | 免费一级a毛片免费观看欧美大片 | 毛片爱爱| 一级做a爰片久久毛片唾 | 亚洲综合色秘密影院秘密影院 | 亚洲乱码视频在线观看 | 天天干天天色综合 | 亚洲小视频在线播放 | 99日影院在线播放 | 在线成人爽a毛片免费软件 在线成人天天鲁夜啪视频 在线成人亚洲 | 国产亚洲精品美女久久久久 | 精品人人| 午夜精品久久久久久久2023 | 日韩欧美一区二区久久黑人 | 一级毛片真人不卡免费播 | 欧美日韩精品一区三区 | 精品福利一区二区三区免费视频 | 欧美一级α片毛片免费观看 | 久久高清一区二区三区 | 91在线亚洲精品一区 | 黄色理伦 | 亚洲成人黄色在线 | 91福利免费| 久久综合亚洲一区二区三区 | 中国jizz18免费 | 一级毛片在线观看视频 | 美女美女高清毛片视频 | 九九资源 | 成人免费视频视频在线观看 免费 | 夜夜操国产 | 一本一道 | 欧洲美女高清一级毛片 | 国产成人免费观看在线视频 | 免费福利视频在线观看 | 精品国产精品久久一区免费式 | 乱子伦xxx欧美 | 国产成人亚洲精品乱码在线观看 |