java - Comparator interface -


OK I was going to edit my last question but I was not sure that this was the right way to do this, So I just ask another question about comparator, now I want to be able to sort in different ways. I have a bank check and if I want to sort with the check mark, check it. I have been able to do it with check number, but how can I find out how to check the amount here for checking the numbers: / P>

  import java util.Comparator; Public Class Check Tool Companator {Private Ent Check Number; Private string description; Private double check amount; Public inquiry () {} public check (int neuq number, double new numount number) {setCheckNumber (newCheckNumber); SetAmountNumber (newAmountNumber); } Public string toString () {return check number + "\ t \ t" + check amount; } Public Zero Satcake number (int check number) {this.checkNumber = checkNumber; } Public int getCheckNumber () {return check number; } Public Zero SetAmountonumber (Double Zodiac Number) {this.checkAmount = Zodiac Number; } Public double getAmountNumber () {return check amount; } @ Override Public Int Comparison (object obj1, object obj2) {int value1 = ((check) obj1) .getCheckNumber (); Int value 2 = ((check) obj2) .getCheckNumber (); Int results = 0; If (value1> value2) {result = 1; } And if (value 1 & lt; value2) {result = -1; } Return results; }} Import java.util.ArrayList; Import java.util.Collections; Import test Check value; Public class test check {public static zero main (string [] args) {ArrayList List = new ArrayList (); List.add (new check (445, 55.0)); List.add (new check (101, 43.12)); List.add (new check (110,101.0)); List.add (new check (553,300.21)); List.add (new check (123,32.1)); collection. Support (list, new check); System.out.println ("Check Number - Check Amount"); For (int i = 0; i  

Thank you very much in advance and please tell me if things are wrongly presented.

What exactly do you want to do different class to Comparator To define the function as the object - its actual vote check is a comparator to the class, but instead there are 3 squares:

  1. Check class itself
  2. a Comparator & lt; Check & gt;
  3. Enables a CheckNumberComparator class (or something similar) that implements class (or something)> comparative

    For sort of sorting, for example, to sort by amount, it will be created ...

      Collections.sort (yourListVariable, new checkmount compiler ()) ; Apart from this, I want to suggest the name of your variable in addition to the highly  list , because the list is a type of name in Java Is used in the form.  


Comments