Convert String to Int to compare values <,>

Discussion in 'Plugin Development' started by tomisanhues3, Nov 25, 2015.

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


    I have these strings
            String X1 = this.getConfig().getString("Location" + ".x");
            String Y1 = this.getConfig().getString("Location" + ".y");
            String Z1 = this.getConfig().getString("Location" + ".z");
    which are obtained from the config.yml file and they are numbers like
    x: 69
    y: 67
    z: 241

    What I need is to convert those Strings into Int so I can then do a bigger than or smaller than that I need
    Thanks in advanced
  2. Offline


    @tomisanhues3 To get an integer from a string, you can use

    Integer.parseInt(String s);
  3. Offline


    Or simply use the method

    getInt("Location" + ".x");
  4. Offline


    @Chloe-chan Unnecessary string concatenation :p (I guess it is assumed that the OP isn't using "Location" though)
    Chloe-chan likes this.
  5. Offline

    Mrs. bwfctower

    But since they are literal strings, they are concatenated at compile-time, and not at runtime.
    Chloe-chan and rbrick like this.
  6. Offline


    Doesn't make it right though. Still bad practice
  7. Offline


    Guys, off-topic...

    I'm simply replying it based on how OP phrased his methods.
  8. Offline


    I don't know if I'd call it bad practise, but it definitely seems superfluous in this case

    Either way, @Chloe-chan 's solution is probably the best one here, regardless of the concatenation thing
  9. Offline

    Mrs. bwfctower

    Not bad practice. In some cases it makes it more readable.
Thread Status:
Not open for further replies.

Share This Page