티스토리 뷰
compareTo() method in Java
compareTo() method compares the Number and an argument. The argument and the number object should be the same types.
Example code
public class Test {
public static void main(String args[]) {
Integer i = 3;
System.out.println(i.compareTo(2)); //returns '1' : Integer is greater than the argument
System.out.println(i.compareTo(3)); //returns '0' : Integer is equal to the argument
System.out.println(i.compareTo(8)); //returns '-1' : Integer is less than the argument
}
}
Reference
https://www.tutorialspoint.com/java/number_compareto.htm
'JAVA' 카테고리의 다른 글
How to convert Arrays to List (0) | 2019.02.26 |
---|---|
Lambda Expression in Java (0) | 2019.02.22 |
Reference Data Type in Java (0) | 2019.02.20 |
Anonymous class in Java (0) | 2019.02.20 |
What's the difference between two different List declaration? (0) | 2019.02.02 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- hackerrank
- easy algorithm
- 프로그래머스 알고리즘
- code refactoring
- 프로그래머스 알고리즘문제
- math.abs
- 프로그래머스
- repeat()
- C++
- java
- 알고리즘
- HackerRank Algorithm
- Javascript Algorithm
- spring boot application
- ... in Javascript
- javascript
- Object type casting
- substring()
- string class in java
- hackerrank javascript
- HashMap
- hackerrank javascript solution
- equals()
- Collection Framework
- math.max
- easy javascript algorithm
- hackerrank solution
- rest parameter
- compareTo()
- algorithm
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함