Saurabh Saxena
Saurabh Saxena

Reputation: 3205

Convert HashTable to a tabular Structure

I have a HashTable in which I have key value pairs like below : The values are separated by tab

<key, value>
Director, Chantal Akerman   Aleksandr Sokurov       Alexandra McGuinness
Country, Belgium-France Russia  UK-Ireland  UK-Ireland

I need to write the values in following structure in a tsv file:

Director             Country
Chantal Akerman      Belgium-France
Aleksandr Sokurov    Russia
                     UK-Ireland
Carol Morley         UK-Ireland

Is there any API available for the same in java. Or is there any other way around?

Upvotes: 2

Views: 106

Answers (1)

Captain Giraffe
Captain Giraffe

Reputation: 14705

The problem easily solved by the standard tools.

Output keys:

List<Scanner> values = new ArrayList<Scanner>();
for( String title: hashTable.keySet() ){
    out.print( title + "\t" );
    Scanner sc = new Scanner(hasTable.get( title );
    sc.useDelimiter("\t");
    values.add();     
}
out.println();

Output values:

while( values.get(0).hasNext() ){
   for(int i = 0; i < values.size(); i++){
      out.print( values.get(i).next() + "\t" );
   }
   out.println();
}

Upvotes: 1

Related Questions