I don't understand what line 9 of the code does
byteCountArray[fileInputStream.read()] += 1;
What does that operation do? i understand that the array takes the values of array + 1 but what does it add? the value at index fileInputStream.read() + 1? what is the purpose of that addition?
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String fileName = bf.readLine();
bf.close();
int[] byteCountArray = new int[256];
try (FileInputStream fileInputStream = new FileInputStream(fileName)) {
while (fileInputStream.available() > 0) {
byteCountArray[fileInputStream.read()] += 1;
}
fileInputStream.close();
}
int maxCount = 0;
for (int byteCount : byteCountArray) {
if (byteCount > maxCount) maxCount = byteCount;
}
ArrayList<Integer> resultList = new ArrayList<>();
for (int i = 0; i < byteCountArray.length; i++) {
if (byteCountArray[i] == maxCount) resultList.add(i);
}
for (Integer resultItem : resultList) System.out.print(resultItem + " ");
}
}