打印哈希表中的多值数据

Print the Multivalued data Inside the Hashtable

I am reading 1 million lines of data from the file it contains data of the movies in a given format FILE DATA IMAGE.

MovieDetails 文件包含简单的获取和设置函数

问题 1 我想打印 hashmap 的数据,但似乎普通方法在这里不起作用,我也想打印多个值(movieTitle 和 Genres)。

问题 2 基本上,当我将 100 万条记录放入散列 table 中时,它会放入所有键,但每个键都包含与最后一个相同的值(参见文件数据图像),当我调试它时,它会显示给我3952(键和值)但在输出中我只得到 1422 但在覆盖我的 class toString() 之后它显示 1539(键和值)。NEW OUTPUT AFTER OVERRIDING 请检查输出图像 OUTPUT IMAGE

MoviesTable DEBUG data Image

请向我解释为什么我会收到这些错误以及如何更正这些错误 谢谢

 MovieDetails mb = new MovieDetails();
        Hashtable<Integer, MovieDetails> moviesTable=new Hashtable<Integer, MovieDetails>();
        try {

            String contentLine;

            br = new BufferedReader(new FileReader("C:/Users/hp/Desktop/movies.dat"));

            while ((contentLine = br.readLine()) != null) {

                mb.setMovieID(Integer.valueOf(contentLine.split("::")[0]));
                mb.setTitle(contentLine.split("::")[1]);
                mb.setGenres(contentLine.split("::")[2]);
                moviesTable.put(mb.getMovieID(), mb);
            }

            for (Entry<Integer, MovieBean> entry : moviesTable.entrySet()) {
                Integer key = entry.getKey();
                MovieBean value = entry.getValue();

                System.out.println ("Key: " + key + " Value: " + value);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }


**OUTPUT IMAGE**
  [1]: https://i.stack.imgur.com/OZi4e.jpg

您的 MovieDetails toString 方法应如下所示:

public String toString() {
       return( "" + getTitle() + " " + getGenres() );
}

也搬家:

MovieDetails mb = new MovieDetails();

 while ((contentLine = br.readLine()) != null) {
      MovieDetails mb = new MovieDetails();
  (then rest of loop)