vendredi 31 juillet 2015

If loop not working as expected java

Reading a lines from a "text.txt" and then storing them into a tremap until the word apply appears how ever after performing this I don't have the last row "4 apply" I want in the treemap

text.txt
1 add 
3 multiply
4 apply
6 add


    Scanner input = new Scanner(file);
        while(input.hasNextLine()){

        String line = input.nextLine();
        String[] divline = line.split(" ");

        TreeMap<Integer, String> valores = new TreeMap();

        if(!divline[1].equals("apply")){
            valores.put(Integer.valueOf(divline[0]), divline[1]);   
        } else {
            valores.put(Integer.valueOf(divline[0]), divline[1]);
            break;
        }

            System.out.println(valores);

        }

Aucun commentaire:

Enregistrer un commentaire