import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
public class Main2 {
public static void main(String[] args){
int[] arr = new int[]{9,0,88,44,55,7,2,3,5,1,0,1,99};
List<Integer> list = new ArrayList<>();
for (int ele: arr)
list.add(ele);
List<Integer> list1 = new ArrayList<>(new LinkedHashSet<>(list));
for(int i=0;i<list1.size();i++)
System.out.print(list1.get(i)+" ");
}
}
关键代码就是将list转为linkedHashSet然后再转为list