I am working on a project where I am creating a TreeMap of past presidents and their blood types. The first step is to generate a map from blood type to presidents, and then to print it out alphabetically. I have that part correct, but I am struggling with the next part. For the second half of the project, I am supposed to then create an inverse mapping where the president is the key and the blood type is the value. I can't seem to figure out how to get this to work without screwing up the first half. I've attached a picture of what the output is supposed to look like. I appreciate any feedback. Output Image
import java.io.*;
import java.util.*;
public class BloodBank
{
public static void main(String[] args) throws Exception
{
BufferedReader infile = new BufferedReader( new FileReader( "type2pres.txt" ) );
TreeMap<String,TreeSet<String>> type2pres = new TreeMap<String,TreeSet<String>>();
while ( infile.ready() )
{
ArrayList<String> tokens = new ArrayList<String>( Arrays.asList( infile.readLine().split(",") ) );
String bloodType = tokens.remove(0);
type2pres.put( bloodType, new TreeSet<String>(tokens) );
}
for ( String type : type2pres.keySet() )
{ TreeSet<String> presidents = type2pres.get( type );
System.out.print( type + "\t" );
for ( String pres : presidents )
{
System.out.print( pres + "\t" );
}
System.out.println();
}
} // MAIN
} // BLOODBANK