Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Pointsjava-repl; rare answer..
treehouse:~/workspace$
treehouse:~/workspace$ java-repl
Welcome to JavaREPL version 303 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65)
Type expression to evaluate, :help for more options or press tab to auto-complete.
java> "banana".compareTo("apple");
java.lang.Integer res0 = 1
java> "apple".compareTo("banan");
java.lang.Integer res1 = -1
java> "apple".compareTo("apple");
java.lang.Integer res2 = 0
java> "2".compareTo("1");
java.lang.Integer res3 = 1
java> "245".compareTo("0");
java.lang.Integer res4 = 2
java> "245".compareTo("1");
java> "245".compareTo("1000");
java.lang.Integer res10 = 1
java> "245".compareTo("0");
java.lang.Integer res11 = 2
java>
1 Answer
Simon Coates
28,695 Pointsi had also thought it was -1, 0, 1, but it just seems to read positive, negative or zero. see https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html . see here for a discussion
Gonzalo Torres del Fierro
Courses Plus Student 16,751 PointsGonzalo Torres del Fierro
Courses Plus Student 16,751 Pointshello, i was toying with the Java-repl tool, and i got this strange answer for the compare method, anybody can help me to understand, why i got a 2 as an asnwer doing: java> "245".compareTo("0"); java.lang.Integer res4 = 2 since i remember in the comparable documentation, they say we can meet "-1","0", or "1" doing this method, but here we got a 2, mmmm