Java comparison using the compareTo () method


public static void main(String[] args) {
        System.out.println("-----a.compareTo(b)Let's use!-----");
		//When a is large
		Integer a = 2;
		Integer b = 1;
		System.out.println("If a is larger" + " " +a.compareTo(b)); //1 returns
       //When a is small
		a = 1;
		b = 2;
		System.out.println("If a is smaller" + " " +a.compareTo(b)); // -1 returns
      //If a and b are the same number
		a = 1;
		b = 1;
		System.out.println("When a and b are the same" + " " +a.compareTo(b)); //0 is returned

compareTo () ・ ・ ・ ・ I still don't know how to use it (laughs)

Recommended Posts

Java comparison using the compareTo () method
Java method
[Java] compareTo
Java method
[Java] method
[Rails 6] destroy using the resources method
Try using IBM Java method tracing
[Java] method
Call the super method in Java
My thoughts on the equals method (Java)
Newcomer training using the Web-Basic programming using Java-
Try using the Stream API in Java
[Java] How to use the toString () method
What is the main method in Java?
[Java] Collection and StringBuilder operation method comparison
Get the error message using the any? method
Try using the Wii remote with Java
Java8 method reference
About the method
[Java] forEach method
[Java] Map comparison
Java framework comparison
java8 method reference
[Java] Random method
[Java] split method
The story of low-level string comparison in Java
[Java] Handling of JavaBeans in the method chain
ChatWork4j for using the ChatWork API in Java
Newcomer training using the Web-Basic programming / classes using Java-
Try accessing the dataset from Java using JZOS
How to use the replace () method (Java Silver)
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Try using the COTOHA API parsing in Java
Output about the method # 2
Sorting using java comparator
[Java] How to use compareTo method of Date class
[Ruby] Cut out a string using the slice method
JAVA DB connection method
The comparison of enums is ==, and equals is good [Java]
[Java] Sort the list using streams and lambda expressions
Try implementing the Eratosthenes sieve using the Java standard library
Java version notation comparison
Java learning memo (method)
[Java] String comparison and && and ||
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Scraping practice using Java ②
About the length method
Java programming (class method)
Using the database (SQL Server 2014) from a Java program 2018/01/04
Scraping practice using Java ①
About the authenticate method.
Training using each_with_index method
Try global hooking in Java using the JNativeHook library
I want to call the main method using reflection
About the map method
[Development] Java framework comparison
About the ancestors method