Search code examples
javaminecraftbukkit

How can I read a list of lists from the config?


Say that I had, in my config.yml file, a list of lists of integers that looked like this:

numbers: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]

How would i go about reading this, or assigning it to a variable?


Solution

  • Since you are getting a List, you should use the ConfigurationSection#getList method. This takes in the path, in your case numbers. This returns a list with captures of ?, so you should cast elements to integer arrays.

    getConfig.getList("numbers").stream().filter(o -> o instanceof List).map(o -> (List) o);
    

    would result in a list of List<?>, so you should transform it to List. You can use the same way of filtering and casting I used above.