The code with abbreviations, then the essence)

public class Main { public static void main(String[] args) throws FileNotFoundException, SQLException { Map<Integer, String> mapTrackFile = new HashMap<Integer, String>(); while (sc.hasNextLine()){ next = sc.nextLine(); if(next.contains(ABBREVIATYRA)){ mapTrackFile = Main.recordDataTrackOrMap(sc, next); } else if(next.contains(STARTS_OF_FRAGMENT)){ db.processString (koltrack, mapTrackFile, mapBD, count, sc); } } static Map recordDataTrackOrMap(Scanner sc, String next) { Map<Integer, String> mapTrackFile = new HashMap<Integer, String>(); //тут нахождение нужных параметров mapTrackFile.put(number, abbreviatura.trim()); return mapTrackFile; } 

MapTrack is taken from a file, it turns out that only the last key pair is recorded - the value, the keys are different 100%, that is, no rewriting takes place. What do I not understand so? Tell me please

    1 answer 1

    So you in the recordDataTrackOrMap method each time return a new map for the key / value and assign it in the main method.
    Solution 2:
    1. Make

      Map<Integer, String> mapTrackFile 

    from the main method by the class field and remove

      Map<Integer, String> mapTrackFile = new HashMap<Integer, String>(); 

    from recordDataTrackOrMap
    2. Pass the mapTrackFile from the main method as a parameter to the recordDataTrackOrMap method, but again

      Map<Integer, String> mapTrackFile = new HashMap<Integer, String>(); 

    remove from recordDataTrackOrMap method

    • Yeah !! Thank you very much! It was stupid of course on my part - Vqq50