版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Andrew_Yuan/article/details/86553539
public class Test1 { public static void main(String[] args) { int num = 500; String first = "179"; String second = "1111"; List<String> telList = new ArrayList<>(); for (int i = 0; i < num; i++) { String third = String.valueOf(getNum(1, 9100) + 10000).substring(1); String tel = first + second + third; telList.add(tel); } for (int j = 0; j < telList.size() - 1; j++) { for (int k = telList.size() - 1; k > j; k--) { if (telList.get(j).equals(telList.get(k))) { telList.remove(k); } } } for (String te : telList) { System.out.println(te); } System.out.println(telList.size()); } public static int getNum(int start, int end) { return (int) (Math.random() * (end - start + 1) + start); } }