I need to create an arraylist, that contains an array of objects to act as the rows of a table, like this:
ArrayList<Object[]> rows = new ArrayList<>();
each of these Object[] arrays will contain the values of the attributes of my Publisher class, like this example:
["123", "McGraw hill", "abc street uncanny valley"]
I know I can do this with either Object.values(p) or Object.keys(p). Since I have all my publishers in an arraylist I tried looping through it to fill the rows ArrayList:
for(Publisher p : publishers){ rows.add(Object.values(p)); } but the ide (Netbeans) says it cannot find the values or key method for the publisher class. The exact error message says:
cannot find symbol symbol: method values(Publisher) location class Object Why can't I use .value() ? Is there another way I can do this? All help is appreciated. Thanks!
keys()andvalues()are not methods of theObjectclass. Can you please post a minimal reproducible example?Object.keysandObject.valuesare functions in JavaScript but not Java. Despite the similar names, these are different programming languages.Object