hi. here is my code.
the output is broken because the value is an array... is iterator the right way?! as said in the first post, i need to get every combination of the hash-values
sample input-text looks like this:
generic data = 1,2,3
generic test = a,b
generic rums = 12,13
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;
public class HashMapEx {
public static void main(String[] args) {
HashMap<String, String[]> metadata = new HashMap<String, String[]>();
try {
// Opening file
// change "/Users/anyexample/input.txt" to path to your test file
BufferedReader in = new BufferedReader(new FileReader("test.txt"));
// string buffer for file reading
String str;
// reading line by line from file
while ((str = in.readLine()) != null) {
//split string from metafile at "="
String[] splitarray = str.split("\\=");
//remove whitespaces from inputfile...
splitarray[0] = splitarray[0].trim();
splitarray[1] = splitarray[1].trim();
//test if splitted string starts with "generic"
//here also the hashmap is filled with the data from generics!
if (splitarray[0].startsWith("generic")){
String[] subsplit1 = splitarray[0].split("\\s+");
splitarray[0] = subsplit1[1];
String[] subsplit2 = splitarray[1].split("\\,");
//splitarray[1] = subsplit2;
for (int index=0; index<subsplit2.length; index++){
System.out.println(splitarray[0] + " " + subsplit2[index]);
}
// fill our hashmap with the wanted data...
metadata.put(splitarray[0], subsplit2);
//}
}
}
System.out.println("found " + metadata.size() + " generics");
Set set = metadata.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
System.out.println(me.getKey() + " : " + me.getValue() );
}
// Close buffered reader
in.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Datei nicht gefunden!");
System.exit(1);
}
}
}