title: list as value of hashMap in Java
body: <p>File: </p>
  
  <pre><code>Person1:AP
  Person2:AP
  Person3:KE
  Person4:KE
  Person5:UK
  Person6:AP
  Person7:UK
  Person8:AP
  </code></pre>
  
  <p>What I have tried is:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.HashMap;
  
  public class TestNull {
  
      public static void main ( String args[]) throws IOException {
  
          BufferedReader br = new BufferedReader ( new FileReader("/home/username/Desktop/test"));
          String str;
          HashMap&lt;String, String&gt; h = new HashMap&lt;String, String&gt;();
  
          try {
              while ( (str = br.readLine()) != null)  {
                  String[] s = str.split(":");
                  h.put(s[1],s[0]);
              }
              System.out.println(h);
          }
  
          catch (FileNotFoundException E) {   
              System.out.println("File Not Found");
          }
          finally {   
              br.close();
          }
      }
  }  
  </code></pre>
  
  <p>I could achieve this by Perl:</p>
  
  <pre><code>use strict;
  use warnings;
  
  open (FILE,"test");
  
  my %hash=();
  while (my $line = &lt;FILE&gt;)   {
  
      chomp $line;
  
      my ($name,$country) = split(":", $line);
  
      chomp ($name,$country);
  
      $hash{$country} .= "$name ";    
  }
  
  for my $keys (keys %hash)   {
  
      print "$keys: $hash{$keys}\n";
  
  }
  </code></pre>
  
  <p>From the data file, I am looking for an out put like this: </p>
  
  <pre><code>{AP = [person1, person 2, person6, person8], KE = [person3, person4], UK = [person5, person7]}
  </code></pre>