Hi, I am trying to add something from a config file into an ArrayList. how might I do this. here is an example config file Code: Example-Players: Example-me: Example-Kills: 2 Example-Deaths: 5 Example-Bank: 20 Example-him: Example-Kills: 3 Example-Deaths: 4 Example-Bank: 29 Example-her: Example-Kills: 1 Example-Deaths: 3 Example-Bank: 10 I would like to add Example-me, Example-him, and Example-Her into an array list, but not add their things like kills and deaths. any help?
bobthefish use ConfigurationSection#getKeys(), it gives you the "keys" in that section, passing in true will give child nodes, so you want to pass in false so that it only gets the direct keys.
I looked at that, but it seems to be a String, not an array list, is that because i probably don't know what I am doing? I tried Code: ArrayList<String> ls = getConfig.getConfigurationSection("Example-Players").getKeys(false); it said that it could not convert from set to arraylist, the only thing is, i don't know what a set is so... idk what to do, besides go learn more java, which Im working on
bobthefish getKeys() returns a Set, not an ArrayList. Set is another form of a collection that prevents duplicate elements. You should still be able to use it as you would a List (aside from method name changes and possibly a few others things)
Ok, I see, what I wanted to do with it is basically be able to put all of the players in an array list in order of highest kill to lowest kill count. I was going to do this by getting all of the names in the config file, then in a for loop putting each kill for each name into an array list, then organizing the array list. can I still do that with a set? I looked at it a little bit, it looks like it should work, thank you xTigerRebornx EDIT: How might I use the ArrayList's get(index) for a Set? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
bobthefish The set is a LinkedHashSet (could change at any time), so AFAIK, there is no equivalent to it. There is probably another way to do what you want, such as using a comparator, or simply making a new ArrayList and transferring the contents.
xTigerRebornx ok, I got it to an array list, but I ran into another problem, this one is with my logic. so I am trying to create a leaderboards sort of thing. so what I need to do is order each player in the array list by his kills. how might I do that? my problem is that I can create a separate array list of integers and order that, but then I have nothing to tie it back to any specific player.
bobthefish http://docs.oracle.com/javase/7/doc...ml#sort(java.util.List, java.util.Comparator) Make your own comparator, that takes the two Players passed in, grabs their value, and compares them in such a way that would return a number greater then 0 if the first Player's value were to be > (< if the first is less than, and 0 if they are equal)