1

I have a Map<String, HashSet<String> > of Names and unique alpha-numeric values correponding to specific entities to which those names could refer, let's call these entry items "IDs".

So for instance, Fyodor Mikhailovich Dostoyevsky would perhaps be related to the ID Q626, because that's a very specific reference, there aren't many widely known figures with that name. Whereas, Bush might be attached to G027, Q290, and Q118, referencing perhaps the man, the beer, and the shrub, in no particular order.

It looks like this:

[Hudson=[Q2672022, Q2915369, Q1181990, Q579848, Q5904041, Q943853, Q76039], Jon S. Corzine=[Q380570], Jon Corzine=[Q380570]]

Is there a preferable way to output this data structure so as to facilitate easy future manipulation. For instance I was just going to print it, with a print writer, but maybe there's a better way of doing this, or a more desirable format that I don't know about. So I'm posing this question.

smatthewenglish
  • 2,831
  • 4
  • 36
  • 72
  • you could output as JSON, as there are many libraries that support reading and writing on JSON – Sanj Apr 23 '15 at 10:43
  • ok cool. I was thinking that. what's one that you would recommend. why is JSON so good tho? – smatthewenglish Apr 23 '15 at 10:44
  • 3
    What do you mean? What is your use case? There are thousands of answers to your question as it currently stands. Define terms - "output", "manipulation", "malleable". What do you require: speed? portability? You could use Java serialization, XML, JSON, Protobuf, custom String format, custom binary format, and countless others. – Boris the Spider Apr 23 '15 at 10:45
  • 1. human readable. 2. supported everywhere. – iced Apr 23 '15 at 10:46
  • @iced I would certainly prefer XML unless true portability is required. But this question is too vague to provide an answer. As it stands Java serialization is probably easiest. – Boris the Spider Apr 23 '15 at 10:47
  • I want to search through them quickly – smatthewenglish Apr 23 '15 at 10:50
  • I'm trying to check them against another database to see if two entities are related – smatthewenglish Apr 23 '15 at 10:51
  • Searching in what way? It seems that the real answer here is "if you need a database, use a database". SQLite will probably be fine for your needs, but you may want to look into MySQL or PostgreSQL. Something like HSQLDB is pure Java and can be embedded, as can Apache Derby. I think you need to define what exactly you want to do. This sort of vague "what's best for my unspecified task" question is off topic here. – Boris the Spider Apr 23 '15 at 10:51
  • @BoristheSpider This ---> http://stackoverflow.com/questions/29814038/create-a-hashmap-with-a-fixed-key-corresponding-to-a-hashset-point-of-departure – Ian2thedv Apr 23 '15 at 11:06
  • @BoristheSpider i was writing those comments from my phone, which is notoriously difficult to type with. sorry for all the misspellings & strange words – smatthewenglish Apr 23 '15 at 11:08
  • @BoristheSpider xml is not human readable. – iced Apr 23 '15 at 12:13
  • @iced excuse me? What do you mean? How is it any less human readable that JSON? It's basically the same structure. This is nonsense. Binary formats are non human readable, string based formats are. – Boris the Spider Apr 23 '15 at 12:15
  • @BoristheSpider there is way to much noise in xml. it's not really human readable due to this. JSON, on other hand, is way easier to read. – iced Apr 23 '15 at 12:54
  • @iced hey man, I would be super interested to get your input on [this question](http://stackoverflow.com/questions/29838841/mapstring-hashsetstring-to-json-pretty-print). I thought JSON would be easy because I always sort of knew what it was, but it's more confusing than I thought. – smatthewenglish Apr 25 '15 at 03:26

0 Answers0