如何使用其中TreeSet
的重复项并将重复项打印出来?
我创建了一个方法,允许我从文本文件中填充没有重复的数组,现在我需要让这些重复项在另一个文件中旋转。我怎么做?
// method that gets that reads the file and puts it in to an array
public static void readFromfile() throws IOException {
// Open the file.
File file = new File("file.txt");
Scanner inputFile = new Scanner(file);
// create a new array set Integer list
Set<Integer> set = new TreeSet<Integer>();
// add the numbers to the list
while (inputFile.hasNextInt()) {
set.add(inputFile.nextInt());
}
// transform the Set list in to an array
Integer[] numbersInteger = set.toArray(new Integer[set.size()]);
// loop that print out the array
for (int i = 0; i < numbersInteger.length; i++) {
System.out.println(numbersInteger[i]);
}
// close the input stream
inputFile.close();
}