0
0

More than 1 year has passed since last update.

String#compareTo()

Posted at

sortに渡すComparatorのbaseになる考え方
returnが1以上になるとsortはひっくり返す

public class Outer {
    public static void main(String[] args) {
        String s1 = new String("A");
        String s2 = new String("B");
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s1));
        System.out.println(s2.compareTo(s1));
    }
}
-1
0
1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0