I tried a little combination with output like -> no space after last number, but it's not validate still.
Maybe you'll see what I don't and in that time I check other help question and think what that it'll would be.
I print it from new list
List <Integer> list = new ArrayList<>();
becouse before that printing result from HashMap (with space after last number), I can't validate too.
package com.codegym.task.task18.task1804;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
/*
Rarest bytes
/home/mati/temporary/file.txt
*/
public class Solution {
public static Map<Integer, Integer> allData = new HashMap<>();
static int min = Integer.MAX_VALUE;
public static void main(String[] args) throws Exception {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String fileName = bufferedReader.readLine();
FileInputStream fileInputStream = new FileInputStream(fileName);
while (fileInputStream.available() > 0) {
int data = fileInputStream.read();
int counter = 1;
if (allData.get(data) == null) {
allData.put(data, counter);
} else {
int value = allData.get(data);
int newValue = ++value;
allData.replace(data, newValue);
}
}
// System.out.println(allData);
for (Integer key : allData.keySet()) {
int value = allData.get(key);
if (value <= min)
min = value;
}
List <Integer> list = new ArrayList<>();
for (Integer key : allData.keySet()) {
int value = allData.get(key);
if (value == min) {
list.add(key);
}
}
for (int i = 0; i < list.size(); i++) {
if (i < list.size() - 1) {
System.out.print(list.get(i) + "\t");
} else {
System.out.print(list.get(i));
}
}
bufferedReader.close();
fileInputStream.close();
}
}