-2

I'm trying to print a hashtable content, that hashtable contains a map inside it, the table is declared just like this:

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

I'm using the next line to print its content, that works for normal (not nested) hashmap, and it's doing something weird with this nested hashmap:

 System.out.println("\n"+mapSD.toString());

EDIT: Just in case it isn't clear enough, I need to print the content in the "{A{BE=2,XD=5}}" way , the toString method do this in not nested maps or hashtables, it works in normal tables, but is overwritting the console output with this nested table.

EDIT 2: The printing should print something like {A{RT=5,CS=3}}, that is, a table of tables. It prints it, but then prints another line over the same line, creating an unreadable mix of characters. I'm using Eclipse Mars.2 IDE, maybe there's something to do with the problem.

Any idea of how to fix this? Thanks in advance.

Amnor
  • 380
  • 6
  • 21
  • 1
    I can't reproduce your issue, what do you have in your map? – Nicolas Filotto Oct 17 '16 at 11:03
  • Something like this: "{AB{SA=4,ZP=3},BA{GU=2,HY=4,HT=1}}" Simply that, different elements inside sets, and the count of them inside those sets, AB has 4 SA elements, and 3 ZP elements, for example. – Amnor Oct 17 '16 at 11:06
  • In the first place, maps don't print anything. In the second place, maps inside hashtables don't print anything either. In the third place, maps whether inside Hashtables or not don't overwrite lines on printing, because they don't print anything in the first place. Unclear what you're asking or even talking about. – user207421 Oct 17 '16 at 12:02
  • @EJP Is quite clear that I want to print the content of the hashtable. The "toString" method, in case you didn't know, returns a String like the one I answered to Nicolas FIlotto. It works very well on unnested maps, but it is not working with this nested one, it prints everything on the same line, mixing the characters and I don't know how to print the contents correctly, you should read more carefully. – Amnor Oct 17 '16 at 12:26
  • 1
    It would be better and make sense if you copy and paste your entire code or atleast the printing part in your question. Suggest you to edit your question – Shreyas Sarvothama Oct 17 '16 at 14:45
  • I don't understand, the printing part is this: "System.out.println("\n"+mapSD.toString());" is posted on the question, what do you mean? Thanks! – Amnor Oct 17 '16 at 15:04
  • I tested it with a Map, it returns {338=14, 337=4, 698=36, 336=4, 697=4, 335=7}. This nested table should return something like {A{338=14, 337=4},B{...}...}, being A and B sets of alphanumeric codes, and the integer after the "=" a count. It reurns it right, but when B should show, instead of writting a new line, it prints in the same line, mixing the characters, and the table becomes unreadable.Thanks! (PD, Sorry, I can't paste the entire code) – Amnor Oct 17 '16 at 15:12
  • @Amnor It is quite clear that your title read, and still reads, 'Map inside hashtable overwritting line on printing'. If you want to fix it, including the spelling error, feel free. But don't blame me for what it says. You wrote it. – user207421 Oct 18 '16 at 09:16
  • @EJP title is a thing, content, is other. When you read the newspaper, do you just read the titles? and I may misspell something because english is not my mother tonge, thanks for the warning. – Amnor Oct 18 '16 at 10:10

1 Answers1

-1

Solved, the problem was the buffer size of the console, that's why it mixed the characters at the same line, the bufer was being overwritted. Thanks for your answers!

Amnor
  • 380
  • 6
  • 21