i have a list of objects:
static List table_rows = new ArrayList();
Which i want to fill with TreeMaps, which consist of a String and an Integer array object:
for (int i = 0; i < observation_files.length; i++) {
TreeMap<String, Integer[]> tm = new TreeMap<String, Integer[]>();
Integer[] cells = new Integer[observation_files.length];
for (int x = 0; x < cells.length; x++) {
cells[x] = 0;
}
tm.put("model" + i, cells);
table_rows.add(tm);
}
now i want to access the int array like so:
table_rows.get(0).get("model1")[0] = 2;
but eclipse does not let me do this and gives me this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method get(String) is undefined for the type Object
Syntax error on token ".", Identifier expected after this token
at HmmPipeline.main(HmmPipeline.java:102)
Code hinting or completion gives me nothing to work with, what am i doing wrong?
Raw
ArrayList.get()returns typeObject. If you want it to returnTreeMap<String, Integer[]>, you should declare your list as:If you use an IDE like Eclipse, it’s a good idea to set your code compilation options to show a warning when you’re using raw (unparameterised) types. Although it should’ve flagged your code up as invalid anyway.
As an aside, what you’re trying to do isn’t a very effective way of storing what’s basically a two-dimensional square array.