Geting 2nd string in list from config

Discussion in 'Plugin Development' started by SeleXOnEuW, Apr 30, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    SeleXOnEuW

    Hey, this is my cut config:
    Code:
      list:
        - Test 10
    
    Now, hot i can get "Test" to another variable, and "10" to another variable?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    SeleXOnEuW

  4. Online

    timtower Administrator Administrator Moderator

    @SeleXOnEuW It splits a string into an array, use the array as you wish.
     
  5. Offline

    SeleXOnEuW

    @timtower
    I do it like this:
    List<String> list = getConfig().getStringList("Config.list");
    String[] list2 = list.toArray(new String[0]);
    String[] list3 = list2.toString().split("Config.list");
    And list3 returns:
    [Ljava.lang.String;@57672e57
     
  6. Online

    timtower Administrator Administrator Moderator

    @SeleXOnEuW
    list2.toString().split("Config.list")
    What is that line supposed to do?
     
  7. Offline

    SeleXOnEuW

    @timtower Jah, i did not understand.
    It is:

    List<String> list = getConfig().getStringList("Config.list");
    String[] parts = list2.split(" ");
    But it doesn't work...
     
  8. Online

    timtower Administrator Administrator Moderator

    @SeleXOnEuW You can't split a list, you can only split the values of that list.
     
  9. 1. Get all strings in the StringList and loop through them:
    Code:java
    1. for (String str : getConfig().getStringList("list")) {
    2.  
    3. }

    2. Split the String str at the whitespace character. The .split method will return a String Array:
    Code:java
    1. String[] split = str.split(" ");

    3. Access the values of the Array:
    Code:java
    1. String test = split[0];
    2. int number = Integer.parseInt(split[1]);

    I suggest you learning more java if you're not familiar with Strings and Arrays.
     
    SeleXOnEuW likes this.
Thread Status:
Not open for further replies.

Share This Page