Getting everything after args[1]

Discussion in 'Plugin Development' started by ThatBox, Dec 13, 2011.

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

    ThatBox

    I want to get everything after args[1] WITHOUT the for(){
    Is there anyway to do this?
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    Arrays.copyOfRange(args, 2, args.length) wil give you the array of all elements from the third element to the end.

    In the case you want a string with the third element onwards.
    Joiner.on(" ").join(Arrays.copyOfRange(args, 2, args.length))

    you will need to import com.google.common.base.Joiner
     
  3. Offline

    ThatBox

    Ahh i saw this on a different thread just you put ARRAY so yah i was confused :/ Lemme check if it works and i'll get back to you.
    EDIT:
    @Sagacious_Zed
    I am adding to a hashmap.
    Code:java
    1. String a = Joiner.on(" ").join(Arrays.copyOfRange(args, 2, args.length));
    2. hash.put(1, a);

    Would it work this way?
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    ThatBox likes this.
  5. Offline

    halley

    Just curious. Why are you trying to avoid the for ( ) loop? The Joiner and the Array.copyOfRange() both use loops to accomplish the same thing. There's nothing wrong with looping... that's how things happen when dealing with arrays.
     
  6. Offline

    ThatBox

    Well I was curious if there was actually another way. :3
     
  7. Offline

    Evangon

    Wait wait wait wait...
    How odd.
    We chose the SAME EXACT TITLE (Punctuation, spelling, everything) xD
    Anyways, for() are more better, so then you can intercept it and make it do something else while it's adding on.
     
Thread Status:
Not open for further replies.

Share This Page