In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the knowledge points of Sorting in Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the knowledge points of Sorting in Java".
Two interfaces Comparable
Code first:
Package java.lang;public interface Comparable {public int compareTo (To);}
You can see that there is only one method for this interface, and this method has only one parameter, so the class that implements this interface can be compared with the same class. What this method implements is the rule of comparison, that is, it represents how to compare two objects. It returns an integer int:
Returns a positive number, indicating that the current object is larger than the object being compared
Returns 0, which means that the current object is equal to the object being compared
Returns a negative number, indicating that the current object is smaller than the object being compared.
Once the interface is implemented, we can use Arrays.sort () and Collections.sort () for sorting. Otherwise, there is no rule of comparison for the object, and the program must not know how to sort the comparison. Like our commonly used classes String, Integer, Double, Date, etc., JDK helps us implement the Comparable interface, and we can compare and sort such objects directly. For example, the implementation of Date Comparable:
Public int compareTo (Date anotherDate) {long thisTime = getMillisOf (this); long anotherTime = getMillisOf (anotherDate); return (thisTime)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.