Created
November 8, 2019 04:56
-
-
Save upangka/64f9db2f7e9e76ed76e4fb4a0fea9cc9 to your computer and use it in GitHub Desktop.
list转set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.caucoder.mylist; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
/** | |
* list转set | |
*/ | |
public class ListToSet { | |
public static void main(String[] args) { | |
List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3,4)); | |
System.out.println(list); | |
Set<Integer> set = list.stream().collect(Collectors.toSet()); | |
System.out.println(set); | |
} | |
} | |
/** | |
[1, 2, 3, 4] | |
[1, 2, 3, 4] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment