使用 TreeSet 生成数组
生活随笔
收集整理的這篇文章主要介紹了
使用 TreeSet 生成数组
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用 TreeSet 生成數(shù)組
import java.util.Random; import java.util.TreeSet; public class RandomSortArray {public static void main(String[] args) {TreeSet<Integer> set = new TreeSet<Integer>();Random ran =new Random();int count =0;while(count<10){boolean succeed = set.add(ran.nextInt(100));if(succeed)count ++;}int size = set.size();Integer[] array = new Integer[size];set.toArray(array);System.out.print("生成不重復(fù)隨機(jī)數(shù)組內(nèi)容如下:");for(int value : array){System.out.print(value + " ");}}}總結(jié)
以上是生活随笔為你收集整理的使用 TreeSet 生成数组的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java中的for-each循环
- 下一篇: 代理IP网站