I am a beginner in Java programming. I want to create a HashMap whose values are String[]'s.
Suppose I have a JTable parametersTable with values in columns 2, 3, and 4 that I wish to fetch from each row. Each three-value set constitutes a HashMap value (String[]).
HashMap<String, String[]> map = new HashMap<String, String[]>();
String[] row = {"one", "two", "three", "four", "five", "six", "seven","eight","nine","ten","eleven"};
for (int i=0; i<row.length; i++) {
map.put(row[i], new String[] {
(String) parametersTable.getValueAt(i, 2),
(String) parametersTable.getValueAt(i, 3),
(String) parametersTable.getValueAt(i, 4)});
}
System.out.println(map);
The above code outputs:
{nine=[Ljava.lang.String;@187930f1, six=[Ljava.lang.String;@2a8000ab, four=[Ljava.lang.String;@4436b0fd, one=[Ljava.lang.String;@134bc965, seven=[Ljava.lang.String;@42e49d45, eleven=[Ljava.lang.String;@68cb58ea, ten=[Ljava.lang.String;@198bbc56, two=[Ljava.lang.String;@54464ee3, three=[Ljava.lang.String;@32aeff9b, five=[Ljava.lang.String;@90ed2c, eight=[Ljava.lang.String;@443d9864}
Why is the output something cryptic and not the values like I expect?
List<String>instead, but that's just mejava.util.Arrays.toString(String[]). BTW: it is not so cryptic, it will print[for Array, then the type (Iis integer and objects print the type asLpackage.Class;. In your case String) and then the system hashcode of the array object after the@.