Solved Loop thru every key

Discussion in 'Spigot Plugin Development' started by Pannkaka, May 8, 2017.

  1. Hello, i know this is really simple but i just can't figure out the logic for it right now..
    How would i loop thru every key in a file when i don't know how many keys it will contain?
     
  2. Do you mean something like this?

    Code (Text):

    for(String key : configuration.getKeys(false)){
     //do something
    }
     
     
  3. Choco

    Moderator

    Use a for-each loop:
    Code (Java):
    for (String key : this.getConfig().getKeys(false)) {
        // Do whatever you want
    }
    EDIT: Snipedddddddddd :c
     
    • Optimistic Optimistic x 1
  4. No, i mean how would i loop thru every key in a file and then loop thru every key that is under that key until i have looped thru "all" the keys.
     
  5. The boolean you pass controls whether you're doing a deep loop (Top level keys, then the keys below that, etc). just change false to true
     
    • Informative Informative x 1
  6. oh, didn't know that, thank you so much! :)