Can someone explain to me, why we need to write 'line.indexOf('#') == 0' in this code? I'm trying to load data from a text file and create objects.
Path path = Paths.get(getClass().getClassLoader().getResource("filmovi.txt").toURI());
//path is content of filmovi.txt
List<String> lines = Files.readAllLines(path, Charset.forName("UTF-8"));
//I put that content in List
for (String line : lines) {
line = line.trim();
if (line.equals("") || line.indexOf('#') == 0) //why we check '#'
continue;
String[] tokens = line.split(";");
Long id = Long.parseLong(tokens[0]);
String naziv = tokens[1];
int trajanje = Integer.parseInt(tokens[2]);
filmovi.put(Long.parseLong(tokens[0]), new Film(id, naziv, trajanje));
if(nextId<id)
nextId=id;
This is the content of the file I am trying to load. I just don't understand why is this ('line.indexOf('#') == 0') important to check?
1;The Shining;146
2;One Flew Over the Cuckoo's Nest;133
3;The Little Shop of Horrors;72
# comment. By no means is it necessary, but it is helpful for hand-written files.#or don't expect lines like this in your input, you don't have to do this.