IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> Java8 jdk1.8新特性 -> 正文阅读

[数据结构与算法]Java8 jdk1.8新特性

Record some significant JDK1.8 operations

Lambda

anonymous inner class

// Original solution
Comparator<Integer> comparator1 = new Comparator<Integer>() {
    @Override
    public int compare(Integer o1, Integer o2) {
        return Integer.compare(o1,o2);
    }
};

// jdk8 solution
Comparator<Integer> comparator2 = (o1, o2) -> {
    return Integer.compare(o1,o2);
};
// Or write like this:
// Comparator<Integer> comparator2 = (o1, o2) -> Integer.compare(o1,o2);

// advanced solution
Comparator<Integer> comparator3 = Integer::compare;

Method Reference

There are three ways to use method reference:

  1. [object]::[normal method name]
  2. [class]::[static method name]
  3. [class]::[normal method name]

Object::method

public static void main(String[] args) {

    // original solution
    Consumer<Integer> consumer = (x) -> System.out.println(x);
    consumer.accept(100);

    // 1st way: [object]::[normal method name]
    // the principle is both the method params list and return type are the same
    // such as, `println` and consumer's standard are the same
    PrintStream ps = System.out;
    Consumer<Integer> consumer2 = ps::println;
    consumer2.accept(200);

    // or
    Consumer<Integer> consumer3 = System.out::println;
    consumer2.accept(200);
    
}
public static void main(String[] args) {
    
    User user = new User();
    Supplier<String> supplier1 = user::getName;
    System.out.println(supplier1.get());

}

static class User{
    private String name = "aaa";
    private Integer age = 10;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

class::static method

Comparator<Integer> comparator3 = Integer::compare;

class::application method

public static void main(String[] args) {

    BiPredicate<String, String> biPredicate = (x,y)->x.equals(y);
    System.out.println(biPredicate.test("cyt", "cyt"));

    BiPredicate<String, String> biPredicate2 = String::equals;
    System.out.println(biPredicate2.test("cyt", "cyt666"));

}

the principle of this kind of way is that:

x is the caller of the method, y is the callee (info by the video, but not my prospective)

constructor reference

public class Test {
    public static void main(String[] args) {

        // Original Usage
        Supplier<User> supplier = () -> new User();
        System.out.println(supplier.get());

        // no args constructor
        Supplier<User> supplier1 = User::new;
        System.out.println(supplier1.get());

        // constructor with args
        Function<Integer,User> function1 = User::new;
        System.out.println(function1.apply(20));

        BiFunction<String,Integer,User> function2 = User::new;
        System.out.println(function2.apply("jinondo",20));

    }

    static class User{
        private String name;
        private Integer age;

        public User(String name) {
            this.name = name;
        }

        public User(Integer age) {
            this.age = age;
        }

        public User(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public User() {
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
}

Array Reference

Function<Integer,String[]> function1 = (x)->new String[x];
String[] array1 = function1.apply(10);
System.out.println(array1.length);

Function<Integer,String[]> function2 = String[]::new;
String[] array2 = function2.apply(20);
System.out.println(array2.length);

Stream

create stream

Four method to create a stream

public static void main(String[] args) {

    // 1. By `stream()` or `parallelStream` of Collection type
    List<String> list = new ArrayList<>();
    Stream<String> stream1 = list.stream();

    // 2. By `stream()` of Arrays, get arrays stream
    User[] users = new User[10];
    Stream<User> stream2 = Arrays.stream(users);

    // 3. by static method `of()` of Stream class
    Stream<String> stream3 = Stream.of("aa", "bb", "cc");

    // 4.1 create unlimited stream
    Stream<Integer> stream4 = Stream.iterate(0, x -> x + 2);
    stream4.limit(10).forEach(System.out::println);

    // 4.2 generate
    Stream.generate(()-> Math.random())
            .limit(5)
            .forEach(System.out::println);

}

Filter

List<User> list = new ArrayList<User>(){{
    add(new User("Curt",20));
    add(new User("Cobain",30));
    add(new User("Bryce",20));
    add(new User("Lucy",40));
}};

// Middle Operation: won't execute any operation
Stream<User> userStream = list.stream().filter((x) -> {
    System.out.println("Middle Operation...");
    return x.age > 20;
});
// Terminal Operation: execute all the operation
// 'Lazy to gain value'
userStream.forEach(System.out::println);

Limit & Skip

List<User> list = new ArrayList<User>(){{
     add(new User("Curt",10));
     add(new User("Cobain",30));
     add(new User("Bryce",20));
     add(new User("Lucy",40));
 }};

list.stream().
        filter(x-> x.age>10)
        .limit(2)
        .forEach(System.out::println);

short circuit

List<User> list = new ArrayList<User>(){{
         add(new User("Curt",10));
         add(new User("Cobain",30));
         add(new User("Bryce",20));
         add(new User("Lucy",40));
 }};

 // happen 'short circuit'
 // means that it will stop when iteration fulfill the limit amount of data
list.stream().
        filter(x-> {
            System.out.println("short circuit");
            return x.age>10;
        })
        .limit(2)
        .forEach(System.out::println);

list.stream()
    .skip(2)
    .forEach(System.out::println);

Distinct

List<User> list = new ArrayList<User>(){{
         add(new User("Curt",10));
         add(new User("Cobain",20));
         add(new User("Bryce",30));
         add(new User("Lucy",40));
         add(new User("Lucy",40));
         add(new User("Lucy",40));
         add(new User("Lucy",40));
 }};
 
 // you have to Override the `equals()` and `hashCode()`
list.stream()
        .distinct()
        .forEach(System.out::println);

Map & FlatMap

List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");

List<User> users = new ArrayList<User>(){{
    add(new User("Curt",10));
    add(new User("Cobain",20));
    add(new User("Bryce",30));
    add(new User("Lucy",40));
}};

list.stream()
    .map(str->str.toUpperCase())
    .forEach(System.out::println);

users.stream()
    //               .map(User::getName)
    .map(user->user.getName())
    .forEach(System.out::println);
public class Test {
    public static void main(String[] args) {

        List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");

        Stream<Stream<Character>> streamStream = list.stream().map(Test::filterCharacter);
        streamStream.forEach(sm->{
            sm.forEach(System.out::println);
        });
    }

    public static Stream<Character> filterCharacter(String str){
        List<Character> list = new ArrayList<>();
        for (Character ch:str.toCharArray()){
            list.add(ch);
        }
        return list.stream();
    }
   
}

flatMap

List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");

Stream<Character> streamStream = list.stream().flatMap(Test::filterCharacter);
streamStream.forEach(System.out::println);

Extension of Flat Map

The difference between add and addAll

List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");

List list1 = new ArrayList(){{
    add(11);
    add(22);
}};

list1.add(list);
System.out.println(list1);

// result is `[11, 22, [aaa, bbb, ccc, ddd]]`
List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");

List list1 = new ArrayList(){{
    add(11);
    add(22);
}};

list1.addAll(list);
System.out.println(list1);

// result is `[11, 22, aaa, bbb, ccc, ddd]`

Sorted

List<User> users = new ArrayList<User>(){{
    add(new User("Cobain",20));
    add(new User("Curt",20));
    add(new User("Bryce",30));
    add(new User("Lucy",40));
}};

users.stream().sorted((user1,user2)->{
    if (user1.age.equals(user2.age)){
        return user1.name.compareTo(user2.name);
    }
    return user2.age - user1.age;
})
.forEach(System.out::println);

Or Default Sort

List<String> list = Arrays.asList("aaa","bbb","ccc","ddd");
// list can't be a custom object list
list.stream().sorted()
.forEach(System.out::printl n);

Find & Match

public static void main(String[] args) {
    List<User> users = new ArrayList<User>(){{
        add(new User("Cobain",20));
        add(new User("Curt",20));
        add(new User("Bryce",30));
        add(new User("Lucy",40));
    }};

    // allMatch
    boolean isMatched = users.stream().allMatch(e -> e.getAge() > 20);
    System.out.println(isMatched);

    // anyMatch
    boolean isMatched2 = users.stream().anyMatch(e -> e.getAge() > 20);
    System.out.println(isMatched2);

    // noneMatch
    boolean isMatched3 = users.stream().noneMatch(e -> e.getAge() > 20);
    System.out.println(isMatched3);

    // findFirst
    Optional<User> op = users.stream().sorted((x, y) -> Integer.compare(y.getAge(), x.getAge())).
        findFirst();
    //        System.out.println(op.get());
    System.out.println(op.orElse(null));

    // findAny
    Optional<User> op2 = users.stream()
        .filter(e -> e.getAge() > 20)
        .findAny();
    System.out.println(op2.get());
    // findAny & parallelStream()
    Optional<User> op3 = users.parallelStream()
        .filter(e -> e.getAge() >= 20)
        .findAny();
    System.out.println(op3.get());

}
 

// count
long count = users.stream().count();
System.out.println(count);

// max
Optional<User> max = users.stream()
        .max((x, y) -> Integer.compare(x.getAge(), y.getAge()));
System.out.println(max.get());

// min
Optional<Integer> min = users.stream()
        .map(User::getAge)
        .min(Integer::compare);
System.out.println(min.get());

Reduce

List<Integer> list = Arrays.asList(1,2,3,4,5,6,7,8,9,10);

List<User> users = new ArrayList<User>(){{
    add(new User("Cobain",20));
    add(new User("Curt",20));
    add(new User("Bryce",30));
    add(new User("Lucy",40));
}};

// Explain:
// the init value is 0, and then 0->x, 1->y, x+y=1 -> x, 2->y, ...
Integer sum = list.stream().reduce(0, (x, y) -> x + y);
System.out.println(sum);
 
Optional<Integer> op = users.stream()
        .map(User::getAge)
        .reduce(Integer::sum);
System.out.println(op.get());

Result

55
110

why the call of reduce can be an actual object or an Optional:

reduce(0, (x, y) -> x + y); have init the original value,

but reduce(Integer::sum); didn’t.

There is a design called map-reduce

Collect

collection

List<User> users = new ArrayList<User>() {{
    add(new User("Cobain", 20));
    add(new User("Curt", 20));
    add(new User("Bryce", 30));
    add(new User("Lucy", 40));
    add(new User("Lucy", 40));
    add(new User("Lucy", 40));
}};

// Collect
List<String> list = users.stream()
        .map(User::getName)
        .collect(Collectors.toList());
list.forEach(System.out::println);

System.out.println("=====================");

Set<String> set = users.stream()
        .map(User::getName)
        .collect(Collectors.toSet());
set.forEach(System.out::println);

System.out.println("=====================");

HashSet<String> hashSet = users.stream()
        .map(User::getName)
        .collect(Collectors.toCollection(HashSet::new));
hashSet.forEach(System.out::println);
List<User> users = new ArrayList<User>() {{
    add(new User("Cobain", 20));
    add(new User("Curt", 20));
    add(new User("Bryce", 30));
    add(new User("Lucy", 40));
}};

// Total
Long count = users.stream()
        .collect(Collectors.counting());
System.out.println(count);

// average
Double avg = users.stream()
        .collect(Collectors.averagingDouble(User::getAge));
System.out.println(avg);

// sum
Integer sum = users.stream().collect(Collectors.summingInt(User::getAge));
System.out.println(sum);

// max User
Optional<User> max = users.stream()
        .collect(Collectors.maxBy((x, y) -> Integer.compare(x.getAge(), y.getAge())));
System.out.println(max.get());

// min User's age
Optional<Integer> min = users.stream()
        .map(User::getAge)
        .collect(Collectors.minBy(Integer::compare));
System.out.println(min.get());

group

static class User {
    private String name;
    private Integer age;
    private String country;
}
List<User> users = new ArrayList<User>() {{
    add(new User("Cobain", 20,"China"));
    add(new User("Curt", 20,"England"));
    add(new User("Bryce", 30,"China"));
    add(new User("Lucy", 40,"America"));
}};

// simple group
Map<Integer, List<User>> map = users.stream().
        collect(Collectors.groupingBy(User::getAge));
System.out.println(map);

// multi level group
Map<String, Map<String, List<User>>> map2 = users.stream().
        collect(Collectors.groupingBy(User::getCountry, Collectors.groupingBy((x) -> {
            if (x.getAge() <= 20) {
                return "Youth";
            }
            if (x.getAge() <= 30) {
                return "Midlife";
            }
            return "Older";
        })));
System.out.println(map2);

result

{20=[User{name='Cobain', age=20, country='China'}, User{name='Curt', age=20, country='England'}], 40=[User{name='Lucy', age=40, country='America'}], 30=[User{name='Bryce', age=30, country='China'}]}


{China={Midlife=[User{name='Bryce', age=30, country='China'}], Youth=[User{name='Cobain', age=20, country='China'}]}, America={Older=[User{name='Lucy', age=40, country='America'}]}, England={Youth=[User{name='Curt', age=20, country='England'}]}}

partition

// partition
Map<Boolean, List<User>> map = users.stream()
        .collect(Collectors.partitioningBy(e -> e.getAge() > 20));
System.out.println(map);

result

{false=[User{name='Cobain', age=20, country='China'}, User{name='Curt', age=20, country='England'}], true=[User{name='Bryce', age=30, country='China'}, User{name='Lucy', age=40, country='America'}]}

statstic

// Summary Statistics
DoubleSummaryStatistics dss = users.stream()
    .collect(Collectors.summarizingDouble(User::getAge));
System.out.println(dss.getSum());
System.out.println(dss.getAverage());
System.out.println(dss.getMax());
System.out.println(dss.getCount());
System.out.println(dss.getMin());

join

List<User> users = new ArrayList<User>() {{
    add(new User("Cobain", 20,"China"));
    add(new User("Curt", 20,"England"));
    add(new User("Bryce", 30,"China"));
    add(new User("Lucy", 40,"America"));
}};

// joining
// result: Cobain-Curt-Bryce-Lucy
String str1 = users.stream()
    .map(User::getName)
    .collect(Collectors.joining("-"));
System.out.println(str1);

// result: ===Cobain,Curt,Bryce,Lucy<<<
String str2 = users.stream()
    .map(User::getName)
    .collect(Collectors.joining(",","===","<<<"));
System.out.println(str2);

Parallel Stream

the underlying implementation of Parallel Stream is Fork/Join

package cyt.java.jdk8;

import java.util.concurrent.RecursiveTask;

/**
 * @ClassName java_advanced
 * @Author Jinondo
 * @Date 2021/7/24 14:22
 */
public class ForkJoinCalculate extends RecursiveTask<Long> {

   private long start;

   private long end;

   private static final long THRESHOLD = 10000;

    public ForkJoinCalculate(long start, long end) {
        this.start = start;
        this.end = end;
    }

    @Override
    protected Long compute() {
        long length = end-start;
        if (length<=THRESHOLD){
            long sum = 0;
            for (long i = start; i <= end; i++) {
                sum += i;
            }
            return sum;
        }

        long middle = (start + end) / 2;
        ForkJoinCalculate left = new ForkJoinCalculate(start, middle);
        left.fork();

        ForkJoinCalculate right = new ForkJoinCalculate(middle+1, end);
        right.fork();

        return left.join() + right.join();

    }
}
public static void main(String[] args) {

    Instant start = Instant.now();

    ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<Long> task = new ForkJoinCalculate(0,10000000L);
    Long sum = pool.invoke(task);
    System.out.println(sum);

    Instant end = Instant.now();
    System.out.println("Time cost: " + Duration.between(start,end).toMillis());

}

When the amount of calculation is large, multi thread operation do works

Use Parallel Stream:

Instant start = Instant.now();

long sum = LongStream.rangeClosed(0, 10000000L)
        .parallel()
        .reduce(0, Long::sum);
System.out.println(sum);

Instant end = Instant.now();
System.out.println("Time cost: " + Duration.between(start,end).toMillis());

Optional

public static void main(String[] args) {
    // `of` will throw null pointer error when criteria is null
    Optional<User> op = Optional.of(new User());
    User user = op.get();
    System.out.println(user);

    Optional<Object> op2 = Optional.empty();
    // `get` will throw `NoSuchElementException`
    // System.out.println(op2.get());

    // `ofNullable` will not throw error when criteria is null
    Optional<User> op3 = Optional.ofNullable(null);
    // but if `get`, throw error `NoSuchElementException`
    // System.out.println(op3.get());

    // `isPresent` and `orElse`
    if (op3.isPresent()){
        System.out.println(op3.get());
    }

    User user1 = op3.orElse(new User("Curt", 20, "America"));
    System.out.println(user1);

    // `orElseGet`
    User user2 = op3.orElseGet(() -> {
        // you can do some other operation as well
        return new User();
    });
    System.out.println(user2);

    // `map` and `flatMap`
    Optional<User> op4 = Optional.ofNullable(new User("Jinondo", 21, "China"));
    Optional<String> str = op4.map((e) -> e.getName());
    System.out.println(str.get());

    Optional<String> str2 = op4.flatMap((e) -> Optional.of(e.getName()));
    System.out.println(str2.get());

}

static class User {
    private String name;
    private Integer age;
    private String country;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(name, user.name) &&
                Objects.equals(age, user.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }


    public User(String name, Integer age, String country) {
        this.name = name;
        this.age = age;
        this.country = country;
    }

    public User() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", country='" + country + '\'' +
                '}';
    }
}

Date / Time Api

First, the new api is thread safe

DateTimeFormatter dtf = DateTimeFormatter.ISO_LOCAL_DATE;

Callable<LocalDate> task = () -> LocalDate.parse("2021-07-24",dtf);

ExecutorService pool = Executors.newFixedThreadPool(10);
List<Future<LocalDate>> result = new ArrayList<>();
for (int i = 0; i < 10; i++) {
    result.add(pool.submit(task));
}

for (Future<LocalDate> future:result){
    try {
        System.out.println(future.get());
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
pool.shutdown();

LocalDateTime Example

// now
LocalDateTime ldt1 = LocalDateTime.now();
System.out.println(ldt1);

//  of
LocalDateTime ldt2 = LocalDateTime.of(2021, 05, 17, 16, 24, 33);
System.out.println(ldt2);

// plus
LocalDateTime ldt3 = ldt2.plusYears(2);
System.out.println(ldt3);

// minus
LocalDateTime ldt4 = ldt2.minusMonths(3);
System.out.println(ldt4);

//  get
System.out.println(ldt2.getDayOfYear());
System.out.println(ldt2.getHour());
System.out.println(ldt2.getSecond());

Intsant

// default UTC Timezone
Instant ins1 = Instant.now();
System.out.println(ins1);

// UTC+8
OffsetDateTime odt1 = ins1.atOffset(ZoneOffset.ofHours(8));
System.out.println(odt1);

long milli1 = ins1.toEpochMilli();
System.out.println(milli1);

Instant ins2 = Instant.ofEpochSecond(60);
System.out.println(ins2); // 1970-01-01T00:01:00Z

Duration / Period

// Duration
Instant ins1 = Instant.now();
try {
	Thread.sleep(1000);
} catch (InterruptedException e) {
	e.printStackTrace();
}
Instant ins2 = Instant.now();
Duration dura1 = Duration.between(ins1, ins2);
System.out.println(dura1.getSeconds());
System.out.println(dura1.toMillis());

// Period
LocalDate ld1 = LocalDate.of(2016, 9, 1);
LocalDate ld2 = LocalDate.now();
Period period = Period.between(ld1, ld2);  // ISO standard
System.out.println(period.getYears());
System.out.println(period.toTotalMonths());

TemporalAdjusters

/**
 * Reuslt:
 * 2021-07-24T21:56:41.366
 * 2021-07-10T21:56:41.366
 * 2021-07-25T21:56:41.366
 * 2021-07-26T21:56:41.366
 */

LocalDateTime ldt1 = LocalDateTime.now();
System.out.println(ldt1);

LocalDateTime ldt2 = ldt1.withDayOfMonth(10);
System.out.println(ldt2);

// next SUNDAY
LocalDateTime ldt3 = ldt1.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
System.out.println(ldt3);

LocalDateTime ldt5 = ldt1.with((ta) -> {
    LocalDateTime ldt4 = (LocalDateTime) ta;
    DayOfWeek dow1 = ldt4.getDayOfWeek();
    if (dow1.equals(DayOfWeek.FRIDAY)) {
        return ldt4.plusDays(3);
    } else if (dow1.equals(DayOfWeek.SATURDAY)) {
        return ldt4.plusDays(2);
    } else {
        return ldt4.plusDays(1);
    }
});
System.out.println(ldt5);

Format

/**
 * Result
 * 2021-07-24T22:00:47.172
 * 2021-07-24 22:00:47
 * 2021-07-24T22:00:47.172
 */

// default
DateTimeFormatter dtf1 = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime ldt1 = LocalDateTime.now();
String str1 = ldt1.format(dtf1);
System.out.println(str1);

// ofPattern
DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime ldt2 = LocalDateTime.now();
String str2 = ldt2.format(dtf2);
System.out.println(str2);

// parse
LocalDateTime newDate = ldt1.parse(str1, dtf1);
System.out.println(newDate);

Timezone

// check all the support Timezone list
Set<String> set = ZoneId.getAvailableZoneIds();
set.forEach(System.out::println);

LocalDateTime ldt1 = LocalDateTime.now(ZoneId.of("Europe/Tallinn"));
System.out.println(ldt1);

/**
* Result
* 2021-07-24T17:07:18.677
* 2021-07-24T17:07:18.680+03:00[Europe/Tallinn]
*/
LocalDateTime ldt2 = LocalDateTime.now(ZoneId.of("Europe/Tallinn"));
ZonedDateTime zdt1 = ldt2.atZone(ZoneId.of("Europe/Tallinn"));
ZonedDateTime zdt2 = ldt2.atZone(ZoneId.of("Asia/Shanghai"));
System.out.println(zdt1);
System.out.println(zdt2);

Convert

// Date convert to LocalDateTime
Date date = new Date();
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
System.out.println(localDateTime);

// LocalDateTime convert to Date
LocalDateTime localDateTime2 = LocalDateTime.now();
ZoneId zoneId2 = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime2.atZone(zoneId2);
Date date2 = Date.from(zdt.toInstant());
System.out.println(date2);

@Repeatable

  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2021-11-19 17:52:03  更:2021-11-19 17:52:59 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/25 19:59:40-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码