Skip to content
Advertisement

From java.util.ArrayList to a dictionary in java

Im using a JBPM to make a SQL query in the DB. The sql output is return to a variable that is java.util.ArrayList. The table that im queryin is like this in MariaDB:

JavaScript

The query that I’m making is SELECT * from school_data. It is returning me in a form of list like [math,1,phycics,4,biology,10…..] and only 20 elements.

Is there a way to transform the output in dictionary and then extract the values easly? I python it would be like this:

JavaScript

Advertisement

Answer

Java does not have lists or dictionaries / maps as built-in data types, so it does not offer syntax or built-in operators for working with them. One can certainly perform transformations such as you describe, but it’s a matter of opinion whether it can be done “easily”. One way would be something like this:

JavaScript

That makes some assumptions about the data types involved, which you might need to adjust for your actual data.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement