Article View: borland.public.jbuilder.java.language
Article #15074Order pb in JDK1.2 Vector
From: Gemplus Software
Date: Thu, 15 Jul 1999 00:00
Date: Thu, 15 Jul 1999 00:00
66 lines
2366 bytes
2366 bytes
Hello Everybody,
Here you may find my prg:
import java.util.*;
public class TestSort {
Vector myV;
HashMap myHashMap;
TreeMap myTreeMap;
public Vector getVector() {
return myV;
}
public TestSort() {
myV = new Vector();
}
public static void main(String[] args) {
TestSort testSort = new TestSort();
final int nNbIter = 20;
testSort.invokedStandalone = true;
for (int i = 0 ; i < nNbIter; i++) {
String myStr = "toto" + String.valueOf(i);
testSort.getVector().addElement(myStr);
}
Object[] mySA = testSort.getVector().toArray();
System.out.println("Array before sorting = " );
for (int i = 0; i < mySA.length; i++)
System.out.print((String)mySA[i] + "|");
Arrays.sort(mySA);
System.out.println("Array after sorting = ");
for (int i = 0; i < mySA.length; i++)
System.out.print((String)mySA[i] + "|");
System.out.println("");
String sToSearch = "toto9";
int nPos = Arrays.binarySearch(mySA, sToSearch);
if ( nPos >= 0 )
System.out.println("Object found = " + (String)mySA[nPos] + ", and
nPos = " + nPos);
}
private boolean invokedStandalone = false;
}
Output :
Sortie :
Array before sorting =
toto0|toto1|toto2|toto3|toto4|toto5|toto6|toto7|toto8|toto9|toto10|toto11|toto12|toto13|toto14|toto15|toto16|toto17|toto18|toto19|
Array after sorting =
toto0|toto1|toto10|toto11|toto12|toto13|toto14|toto15|toto16|toto17|toto18|toto19|toto2|toto3|toto4|toto5|toto6|toto7|toto8|toto9|
Object found = toto9, and nPos = 19
The pb is that I have not the same order !!! May I have to write a new
compareTo method in a String derived class. So, is there anybody who may
give me a solution ?
Best Regards.
Technical Details
Message-ID:
<378DF29E.3DD0FB12@gemplus.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,3f216d47b178afc5,start X-Google-Attributes: gidf74b3,public From: Gemplus Software <gemplus.software@gemplus.com> Subject: Order pb in JDK1.2 Vector Date: 1999/07/15 Message-ID: <378DF29E.3DD0FB12@gemplus.com> X-Deja-AN: 501343960 Content-Transfer-Encoding: 7bit Organization: Another Netscape Collabra Server User X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language