|
You really need to adopt the OO approach and define your IRGPerf class to implement the Comparator interface. Just declare your class as class IRGPerf implements Comparator {... Then, somewhere in your IRGPerf class you declare and equals and a compare method. So for your case you would have something like: public int compare(Object obj1, Object obj2) { if (!(obj1 instanceof IRGPerf)) { return 0; // Leave unknown object alone, or throw an exception here } if (!(obj2 instanceof IRGPerf)) { return 0; // Leave unknown object alone, or throw an exception here } IRGPerf irgPerf1 = (IRGPerf)obj1; IRGPerf irgPerf2 = (IRGPerf)obj2; if (irgPerf1.strNbr > irgPerf2.strNbr) { return 1; } else if (irgPerf1.strNbr == irgPerf2.strNbr) { return 0; } else (irgPerf1.strNbr > irgPerf2.strNbr) { return -1; } } Note: if you don't like the multiple return style, just change this to use a local result variable. public boolean equals(Object object) { if (!(object instanceof IRGPerf)) { return false; // Obviously a comparision of an unknown object should fail } IRGPerf anIRGPerf = (IRGPerf)object; return (this.strNbr == anIRGPerf.strNbr); } Feel free to yell at me for any syntax or procedural errors. Then, where you need it, use a ListArray instead of a Vector (or convert it). Then just code: Collections.sort(yourList); It's that simple! Your Comparator methods in the IRGPerf class will be called to compare the internal object values. I have similar code to this which sorts fairly large lists inside of a GUI. Even on an average system the Java Collections sort method has sorted lists of 10,000 in a second or less. Jeff Furgal Product Architect Lakeview Technology, Inc. "Premature optimization is the root of all evil" - Donald Knuth
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.