Java CompareTo Method

does anyone know how the string compareTo method actually works? I am trying to use a binary search to find a word in an arraylist with a specific prefix.
i know that the compareTo method returns a 1 0 or -1 based on what the result of the comparison is but im interested in teh actual way that the comparison takes place.
Since i will be comparing a prefix to a complete word, i would like to know if this would cause any problems due to the difference in string lengths.
Do you guys have any other idea on how i can use a very fast searching method to search a sorted arraylist of words to see if any word with a specific prefix exists?

i did that but i would still have to use compareTo because if the middle element does not have the prefix i am looking for then i would have to know if its on the right half or the left half of the Arraylist by comparing. right?
     public static int bSearch(ArrayList list, String pref)
          int result = -1;
          int low = 0;
          int high = list.size()-1;
          String s="";
          while(low <= high || result==-1)
               int mid = (low + high)/2;
               s = (String)list.get(mid);
               if(s.startsWith(pref)==true)
                    result = mid;
               else if(pref.compareTo(list.get(mid))<0)
                    high = mid - 1;
               else
                    low = mid + 1;
          return result;
     }this is what i got so far but i am not sure if using compareTo method the way i am using it will work or not.

Similar Messages

  • I must be losing my mind, Integer  not having a compareTo method?

    import java.util.Comparator;
    @SuppressWarnings("hiding")
    public class IntComparator<Integer> implements Comparator<Integer>
    @Override
    public int compare(Integer o1, Integer o2)
         o1.compareTo(o2);
    Eclipse is claiming that the Integer class does not have a compareTo(Integer) method.

    >
    @Override
    public int compare(Integer o1, Integer o2)
    Eclipse is claiming that the Integer class does not have a compareTo(Integer) method.It will be complaining that Integer does not have a compare method, the specific method you are trying to override that does not exist.
    However the Integer class does have a compareTo() method that you can override, refer to the API
    Mel

  • CompareTo method to compare files

    I have to compare each line from two files and say whether the lines are different or not. I don't exactly understand how to use the compareTo method in this type of situation. I'd appreciate any help.
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import java.util.StringTokenizer;
    public class FileComparer
    public static void main (String[] args)
    String line, file="http://condor.depaul.edu/~jpetlick/extra/224/display.txt";
    String line2, file2="http://condor.depaul.edu/~jpetlick/extra/224/display2.txt";
    int lineCount = 0, wordCount = 0, lineCounter = 0;
    try
    URL URLfile = new URL (file);
    InputStream input = URLfile.openStream();
    BufferedReader buffer = new BufferedReader(new InputStreamReader(input));
    line = buffer.readLine();
    URL URLfile2 = new URL (file2);
    InputStream input2 = URLfile2.openStream();
    BufferedReader buffer2 = new BufferedReader(new InputStreamReader(input2));
    line2 = buffer2.readLine();
    while (line != null)
    if (line != line2)
    System.out.println("at Line " + lineCounter);
    System.out.println("DISPLAY.TXT " + line);
    System.out.println("DISPLAY2.TXT " + line2);
    lineCounter++;
    StringTokenizer st = new StringTokenizer(line);
    wordCount += st.countTokens();
    lineCount++;
    line = buffer.readLine();
    line2 = buffer2.readLine();
    System.out.println("\nA total of " + lineCounter + " were different between DISPLAY.TXT and DISPLAY2.TXT");
    System.out.println("DISPLAY.TXT contains:");
    System.out.println("\nTotal number of lines: " + lineCount);
    System.out.println("Total number of words: " + wordCount);
    catch (FileNotFoundException exception)
    System.out.println("The file " + file + " was not found.");
    catch (IOException exception)
    System.out.println(exception);
    }

    Change the lineif (line != line2)to if (!line.equals( line2))since strings are immutable in java "line != line2" will alwais evaluate to false in your case.
    equals actually compares the contents of the string.
    Kurt.

  • Understanding Comparable and the compareTo( ) method

    I have a Contact object which lists a person's information for a "phone book" program.
    I am trying to sort the Contact objects in a Vector by way of their last name fields.
    I am having a hell of a time trying to use this compareTo( ) method.
    I'm really struggling with understanding how to go about making the method work with a comparison. Most of the examples which I find compare "numbers' and not strings which make it more difficult to understand.
    I have implimented the comparable Interface at the start of my class. To sort my Vector, I'm attempting to use the compareTo( ) method to determine which Last name field has the lower value. I keep going back and forth working through the error messages I receive and I'm just stumped trying to figure out how to get this thing to work. Can someone please point out the mistakes without writing too much code? I don't want someone to do the work for me. Here is the code:
    import java.io.*;
    import java.util.*;
    class PhoneBook implements Comparable{
         private static Vector v = new Vector();
         private static Iterator iter = v.iterator();
         private static int num, index;
         private static Contact firstContact, secondContact, temp;  //"static" to be referenced from main
         public static void main(String arg[])throws Exception {
              Contact c;
              String str;
              BufferedReader br = new BufferedReader(
          new InputStreamReader(
               new FileInputStream(
                                           new File("contacts.txt"))));
              while((str = br.readLine()) != null){
               v.add(c= new Contact(br.readLine()));
               num = v.size();
               for(int i=0; i < num; i++){
          firstContact = (Contact)v.elementAt(i);
               if(v.elementAt(++i) == null)
                    break;
               else
                    secondContact = (Contact)v.elementAt(++i);
               index = compareTo(firstContact);
               if(index == 1){
                       temp = (Contact)v.elementAt(i);
                       v.setElementAt(v.elementAt(++i), i);
                       v.setElementAt(temp, ++i);
              public static int compareTo(Object person){
         int x = ((Contact)person).getLName().compareTo(secondContact.getLName());
         return x;
    }yet still I get the following compiler error:
    PhoneBook.java:4: compareTo(java.lang.Object) in PhoneBook cannot implement compareTo(java.lang.Object) in java.lang.Comparable; compareTo(java.lang.Object) and compareTo(java.lang.Object) are static
    class PhoneBook implements Comparable{
    ^
    1 error

    You are pretty close here except for one incorrect basic assumption. Your compiler error is because you are trying to implement compareTo() with a static method. However, this is irrelevant because it is not the PhoneBook class that should implement Comparable, but the Contact class.
    The idea is that other functions can call the compareTo() method on an instance of Contact and pass a reference to a second instance. Based on the result, the relative sort order of the two objects can be determined.
    e.g.Contact c1 = new Contact("Smith", "John");
    Contact c2 = new Contact("Jones", "Alan");
    int x = c1.compareTo(c2);In your example, you can implement compareTo() to use the corresponding method in String. For compatibility, you should also implement equals().
    public class Contact implements Comparable {
       public int compareTo(Object otherContact) {
           Contact otherC = (Contact) otherContact;  // could throw exception
           return getLName().compareTo(otherC.getLName());
       public boolean equals(Object otherContact) {
           Contact otherC = (Contact) otherContact;  // could throw exception
           return getLName().equals(otherC.getLName());
    } // end of class Contact I haven't compiled or tested the above code nor does it deal with exceptions (e.g. otherContact is not an instance of Contact) - I'll leave that to you! You'll also need to change your PhoneBook sort routine to invoke firstContact.compareTo(secondContact)
    FYI - I understand that this is an academic exercise and so you may need to code the sort yourself, but once Contact implements Comparable, you could sort the Vector using standard Java methods. Check out java.util.Collections - there is a method that will perform your sort in one line of code.
    Good Luck.

  • Overriding compareTo method for ints

    I'm having a problem writing the overloaded compareTo method for my class. Ideally, the class will be used in collections, and has to be sorted by an int value. I've found a messy way to do this by converting the int values into strings, then comparing those, but I would like to know if there is a better way to do this.

    You could subtract, unless you are worried about over/underflow.
    Then you can just compare the ints the old-fashioned way:
    import java.util.*;
    public class Test implements Comparable<Test> {
        int x;
        public int compareTo(Test that) {
            return this.x - that.x;
            //return this.x < that.x ? -1 : this.x > that.x ? 1 : 0;
    }

  • Calling a java static method from javascript

    I am running into issue while calling a java static method with a parameter from javascript. I am getting the following error. Any help is greatly appreciated.
    Thx
    An error occurred at line: 103 in the jsp file: /jnlpLaunch.jsp
    pfProjectId cannot be resolved to a variable
    =================================================
    // Java static method with one parameter
    <%!
    public static void CreateJnlpFile(String pfProjectId)
    %>
    //Script that calls java static method
    <script language="javascript" type="text/javascript">
    var pfProjectId = "proj1057";
    // Here I am calling java method
    <%CreateJnlpFile(pfProjectId);%>
    </script>
    ===================================================
    Edited by: 878645 on Mar 6, 2012 11:30 PM

    Thanks, Got what you are telling. Right now I have one jsp file which is setting the parameter 'pfProjectId' and in another .jsp I am retrieving it. But I am getting null valuue
    for the variable. I am wondering why I am getting null value in the second jsp page?.
    Thx
    ====================================================================
    <script language="javascript" type="text/javascript">
    // Setting parameter pfProjectId
    var pfProjectId = "proj1057";
    request.setParameter("pfProjectId", "pfProjectId");
    </script>
    // Using Button post to call a .jsp that creates jnlp file
    <form method=post action="CreateJnlpFile.jsp">
    <input type="submit" value="Create JNLP File">
    </form>
    //Contents of second .jsp file CreateJNLPFile.jsp
    String pfProjectId = request.getParameter("pfProjectId ");
    System.out.println( "In CreateJnlpFile.jsp pfProjectId " + pfProjectId );
    =======================================================

  • How to generate all the links of the java api methods

    Hi all,
    I noticed from my docs that the JAVA API methods are not linked. They are just static text. How can i link all the java api methods to a root url examble: java.sun.com/j2se/docs/javax/JFrame#pack()
    java.sun.com/j2se/docs/javax/JFrame#setVisible()
    java.sun.com/j2se/docs/java/sql/ResultSet#executeQuery()
    and so on.
    Thank you in advance.

    It sounds like you'd like to link to our docs on java.sun.com.
    You can do this using -link or -linkoffline
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javadoc.html#link
    Start by reading the section "Choosing between -linkoffline and -link"
    Basically, try this option first:
    -link http://java.sun.com/j2se/1.4/docs/api
    If this fails (because your shell cannot access java.sun.com),
    then copy package-list from java.sun.com to your current directory,
    then use this option:
    -linkoffline http://java.sun.com/j2se/1.4/docs/api .
    Notice that the second argument is a dot "." to indicate
    that package-list is in the current directory.
    -Doug Kramer
    Javadoc team

  • How to write javascript in java class method

    Hi,
    any one please resolved this,
    i want to write javascript window closing code into java class method, in that method i want to write javascript code & wanted to call in jsf page on commandButton action event,
    my code is below but it is not working properly
    public void closeWindowClicked(ActionEvent event) {
              try
         FacesContext facesContext = FacesContext.getCurrentInstance();
         String javaScriptText = "window.close();";
         // Add the Javascript to the rendered page's header for immediate execution
         AddResource addResource = AddResourceFactory.getInstance(facesContext);
         addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javaScriptText);
    catch(Exception e)
         System.out.println(""+e);
    for calling into jsf code is below
    <h:commandButton action="#{parentBean.closeWindowClicked}" value="OK" />
    /*Note- i want to closed the window by caling method contain javascript only, i don't want any ajax code in method */
    please any one can resolved this.
    Thanks

    /*Note- i want to closed the window by caling method contain javascript only, i
    don't want any ajax code in method */ When the user presses your button, do your business logic and then send them to a page containing the following (note: untested code ahead):
    <html>
    <head>
        function onLoadHandler()
            window.close();
    </head>
    <body onload="onLoadHandler();">
        <p>Window closing....</p>
    </body>
    </html>

  • Setting Control-Flow- Case on java class/method

    hello All :D
    i have little problem about control flow case, in my case i've 2 page where before load to the page i'wanna make condition (if-else)
    when the user choose the field, the java class get the value for make true condition. In this case, i wanna implement ControlFlowCase in java class/method, so anyone help..?
    thx
    agungdmt

    Have you considered using router activity - http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/taskflows_activities.htm#CJHFFGAF ?

  • Java application hangs during running java native method

    Hello,
    There is compiled java application.
    It hangs at very begginings.
    It was detected that in the beggining a new Frame should be created. Then one java library invokes native method. During invoking of the native method application hangs.
    Stack is available only until native method invocation.
    Thread 25196 "main": (state = IN_NATIVE)
    at sun.awt.X11GraphicsDevice.getDoubleBufferVisuals(Native Method)
    at sun.awt.X11GraphicsDevice.getDefaultConfiguration(X11GraphicsDevice.java:181)
    at java.awt.Window.init(Window.java:271)
    at java.awt.Window.<init>(Window.java:319)
    at java.awt.Frame.<init>(Frame.java:419)
    at javax.swing.JFrame.<init>(JFrame.java:194)
    at com.test.ORBManager.Splash.<init>(Splash.java:10)
    at com.test.ORBManager.Splash.main(Splash.java:48)
    Method getDoubleBufferVisuals(int screen) is used to enumerates all visuals that support double buffering (according to comments in the source code).
    Tried to run with "-verbose" options...
    I tried to use jconsole &#1080; jvisualvm. But did not find anything special.
    Also "strace" command showed some results but do not know how to proceed:
    select(6, [5], [5], NULL, NULL) = 1 (out [5])
    writev(5, [{"b\0\6\0\r\0\0\0DOUBLE-BUFFER\0\0\0", 24}], 1) = 24
    select(6, [5], [], NULL, NULL) = 1 (in [5])
    read(5, "\1\0\t\0\0\0\0\0\1\211\0\204\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096) = 32
    read(5, 0x83b57bc, 4096) = -1 EAGAIN (Resource temporarily unavailable)
    gettimeofday({1275494877, 569746}, NULL) = 0
    select(6, [5], [5], NULL, NULL) = 1 (out [5])
    writev(5, [{"b\0\6\0\r\0\0\0DOUBLE-BUFFER\0\0\0", 24}], 1) = 24
    select(6, [5], [], NULL, NULL) = 1 (in [5])
    read(5, "\1\0\n\0\0\0\0\0\1\211\0\204\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096) = 32
    read(5, 0x83b57bc, 4096) = -1 EAGAIN (Resource temporarily unavailable)
    select(6, [5], [5], NULL, NULL) = 1 (out [5])
    writev(5, [{"\211\6\3\0\1\0\0\0&\0\0\0", 12}], 1) = 12
    select(6, [5], [], NULL, NULL) = 1 (in [5])
    read(5, "\1\0\v\0\f\0\0\0\1\0\0\0\377\32\0\0\377\r\307 \0\0\0\0\0\23\372\300\376\3346\34"..., 4096) = 44
    read(5, 0x83c31e4, 36) = -1 EAGAIN (Resource temporarily unavailable)
    select(6, [5], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted)
    I have downloaded from the internet the source code of native method but do not know what I can do with it.
    Is it possible to debug native method somehow?
    How to detect where the library contans the native method is located?
    What other ways can provide more information about reason.
    It seems that the problem is related to graphics. Judging by class name "X11GraphicsDevice" it is related to X server. May be some server settings?
    The problem is present on SLED 11 machines.
    It is not reproduced on SLED 10.
    I will be really appreciate for any help.
    Thanks in advance.
    Vasily.

    Hi,
    Thanks for tip. I used jstack. It gives a little bit more info but I have to few knoledges how to treat the info.
    ----------------- 24231 -----------------
    ----------------- 24317 -----------------
    0xffffe430     ????????
    0x6dd12229     ????????
    0xb0ca5898     * java.net.PlainSocketImpl.socketAccept(java.net.SocketImpl) bci:0 (Interpreted frame)
    0xb0c9fb6b     * java.net.PlainSocketImpl.accept(java.net.SocketImpl) bci:7 line:384 (Interpreted frame)
    0xb0c9fb6b     * java.net.ServerSocket.implAccept(java.net.Socket) bci:50 line:450 (Interpreted frame)
    0xb0c9fb6b     * java.net.ServerSocket.accept() bci:48 line:421 (Interpreted frame)
    0xb0c9fa94     * sun.rmi.transport.tcp.TCPTransport.run() bci:59 line:340 (Interpreted frame)
    0xb0c9fe71     * java.lang.Thread.run() bci:11 line:595 (Interpreted frame)
    0xb0c9d236     <StubRoutines>
    0xb6f38eac     _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x1bc
    0xb7108aa8     _ZN2os20os_exception_wrapperEPFvP9JavaValueP12methodHandleP17JavaCallArgumentsP6ThreadES1_S3_S5_S7_ + 0x18
    0xb6f38705     _ZN9JavaCalls12call_virtualEP9JavaValue11KlassHandle12symbolHandleS3_P17JavaCallArgumentsP6Thread + 0xd5
    0xb6f3879e     _ZN9JavaCalls12call_virtualEP9JavaValue6Handle11KlassHandle12symbolHandleS4_P6Thread + 0x5e
    0xb6fb0765     _Z12thread_entryP10JavaThreadP6Thread + 0xb5
    0xb71a9373     _ZN10JavaThread3runEv + 0x133
    0xb71096b8     _Z6_startP6Thread + 0x178
    0xb781a1b5     start_thread + 0xc5
    ----------------- 24318 -----------------
    0xffffe430     ????????
    0x1b7bfaf0     ????????
    ----------------- 24373 -----------------
    0xffffe430     ????????
    0xb71087be     _ZN2os5Linux14safe_cond_waitEP14pthread_cond_tP15pthread_mutex_t + 0xae
    0xb70fe2af     _ZN13ObjectMonitor4waitExiP6Thread + 0xa6f
    0xb718bdc6     _ZN18ObjectSynchronizer4waitE6HandlexP6Thread + 0x56
    0xb6f925e3     JVM_MonitorWait + 0x163
    0xb0ca5898     * java.lang.Object.wait(long) bci:0 (Interpreted frame)
    0xb0c9fb6b     * java.lang.ref.ReferenceQueue.remove(long) bci:44 line:120 (Interpreted frame)
    0xb0c9fa94     * java.lang.ref.ReferenceQueue.remove() bci:2 line:136 (Interpreted frame)
    0xb0c9fa94     * sun.java2d.Disposer.run() bci:3 line:125 (Interpreted frame)
    0xb0c9fe71     * java.lang.Thread.run() bci:11 line:595 (Interpreted frame)
    0xb0c9d236     <StubRoutines>
    0xb6f38eac     _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x1bc
    0xb7108aa8     _ZN2os20os_exception_wrapperEPFvP9JavaValueP12methodHandleP17JavaCallArgumentsP6ThreadES1_S3_S5_S7_ + 0x18
    0xb6f38705     _ZN9JavaCalls12call_virtualEP9JavaValue11KlassHandle12symbolHandleS3_P17JavaCallArgumentsP6Thread + 0xd5
    0xb6f3879e     _ZN9JavaCalls12call_virtualEP9JavaValue6Handle11KlassHandle12symbolHandleS4_P6Thread + 0x5e
    0xb6fb0765     _Z12thread_entryP10JavaThreadP6Thread + 0xb5
    0xb71a9373     _ZN10JavaThread3runEv + 0x133
    0xb71096b8     _Z6_startP6Thread + 0x178
    0xb781a1b5     start_thread + 0xc5
    ----------------- 24227 -----------------
    0xffffe430     ????????
    0x6cbc4021     ????????
    0x6cbc232a     ????????
    0x6cbc3c9a     ????????
    0x6cc1d5d1     ????????
    0x6d41013f     ????????
    0x6d460f19     ????????
    0xb0ca5898     * sun.awt.X11GraphicsDevice.getDoubleBufferVisuals(int) bci:0 (Interpreted frame)
    0xb0c9fb6b     * sun.awt.X11GraphicsDevice.getDefaultConfiguration() bci:140 line:181 (Interpreted frame)
    0xb0c9fa94     * java.awt.Window.init(java.awt.GraphicsConfiguration) bci:51 line:271 (Interpreted frame)
    0xb0c9fb6b     * java.awt.Window.<init>() bci:66 line:319 (Interpreted frame)
    0xb0c9fb6b     * java.awt.Frame.<init>(java.lang.String) bci:1 line:419 (Interpreted frame)
    0xb0c9fb6b     * javax.swing.JFrame.<init>(java.lang.String) bci:2 line:194 (Interpreted frame)
    0xb0c9fb6b     * com.test.ORBManager.Splash.<init>() bci:3 line:10 (Interpreted frame)
    0xb0c9fb6b     * com.test.ORBManager.Splash.<init>(java.lang.String[]) bci:4 line:48 (Interpreted frame)
    0xb0c9d236     <StubRoutines>
    0xb6f38eac     _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x1bc
    0xb7108aa8     _ZN2os20os_exception_wrapperEPFvP9JavaValueP12methodHandleP17JavaCallArgumentsP6ThreadES1_S3_S5_S7_ + 0x18
    0xb6f38cdf     _ZN9JavaCalls4callEP9JavaValue12methodHandleP17JavaCallArgumentsP6Thread + 0x2f
    0xb6f638b2     _Z17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread + 0x152
    0xb6f54ac2     jni_CallStaticVoidMethod + 0x122
    0x08049873     ????????
    0xb76c9705     ????????The last stack also has "sun.awt.X11GraphicsDevice.getDoubleBufferVisuals(int) bci:0 (Interpreted frame)" but what tode next?
    Also I found that the native code is in java 1.5 source code: \j2se\src\solaris\native\sun\awt\awt_GraphicsEnv.c.
    How it is possible to compile it?

  • Doubt in compareTo method while sorting string having special character

    I used compareTo method of String to sort below strings
    ??che
    ??in
    p?ch?
    I got the output in the below order :
    p?ch?
    ??che
    ??in
    Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
    and that of *?* is *130* so shouldn't ??in appear ??che?
    Regards,
    Joshua

    jaay wrote:
    I used compareTo method of String to sort below strings
    ??che
    ??in
    p?ch?
    I got the output in the below order :
    p?ch?
    ??che
    ??in
    Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
    and that of *?* is *130* so shouldn't ??in appear ??che?
    Regards,
    JoshuaAre you sure your strings are using ASCII encoding, and not unicode? If it's the latter, the ASCII table won't matter at all and you'd need to check the values in a unicode table.

  • ADF: Can i call javascript function from java clsss method in ADF?

    Hi,
    I want to call javascript function in Java class method, is it possible in ADF? , if yes then how?
    or I need to use Java 6 feature directely?
    Regards,
    Deepak

    private void writeJavaScriptToClient(String script)
    FacesContext fctx = FacesContext.getCurrentInstance();
    ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
    erks.addScript(fctx, script);
    }usage
    StringBuilder script = new StringBuilder();
    script.append( "var popup = AdfPage.PAGE.findComponentByAbsoluteId('p1');");
    script.append("if(popup != null){"); script.append("popup.show();"); script.append("}");
    writeJavaScriptToClient(script.toString());Timo

  • Problems accessing my compareTo method

    Could you any one help me on this please.
    I have 3 classes :
    1- "Test class" that creates the object (works fine) and redefines compareTo method
    2. "XListeChainee" that manage my linked list :
    - insert a new node (problems) in order
    3. "Test" which is the classe containing the main method. here is the code
    class Test {
    public static void test(){
    XListeChainee liste = new XListeChainee();
    liste.insererOrdonne(new TestClass("A"));
    liste.insererOrdonne(new TestClass("B"));
    liste.insererOrdonne(new TestClass("C"));
    liste.insererOrdonne(new TestClass("E"));
    liste.insererOrdonne(new TestClass("D"));
    // ------- here is the main method
    public static void main(String[] args){//main
    Test obj = new Test();/
    obj.test();
    }//end main
    here is the class TestClass with the compareTo method
    class TestClass implements Comparable{
    String data;
    TestClass(String data)
    this.data = data;
    }//end constructor
    public String toString(){
    return (data);
    public int compareTo(Object o) {
    TestClass n = (TestClass)o;
    int compData = data.compareTo(n.data);
    return compData ;
    }//end TestClass
    and this is my XListeChainee class (some of the code)
    public class XListeChainee
    private Noeud premierNoeud; //reference to first node
    private Noeud dernierNoeud; //reference to last node
    boolean estVide(){
    return premierNoeud == null;
    // ------ Insert an object: in order
    void insererOrdonne(Object element) {        
    // Creates a new node with the new element
    Noeud unNoeud;
    unNoeud = new Noeud();
    unNoeud.majElement(element) ;
    if ( premierNoeud == null ) { // if first node = null
    premierNoeud = unNoeud; // new node become first
    //------------------------- problem------------------------------
    //---- Compare the element in the first node with the element : Doesn't work
    // ---- System says that cannot resolve symbol - compareTo
    // This line says: if (firstNode.element.compareTo(element)>=0)
    else if ( premierNoeud.obtenirElement().compareTo(element) >= 0 ) {
    // Le nouvel element est < que le 1er element, alors il est inser� a la tete
    unNoeud.majSuivant(premierNoeud);
    premierNoeud = unNoeud;
    else {
    // Chercher la position du nouvel element dans la liste
    Noeud parcourir; // un noeud pour parcourir la liste
    Noeud prec; //un noeud toujour avant celui qui parcours la liste
    parcourir = premierNoeud.obtenirSuivant();
    prec = premierNoeud;
    while (parcourir != null && parcourir.obtenirElement().compareTo(element) < 0) {
    previous = parcourir;
    parcours = parcourir.obtenirSuivant();
    unNoeud.majSuivant(parcourir); // Insert newNode after previous.
    prec.majSuivant(unNoeud);
    Could you help me doing this please? I' sorry about some variable and method's names but I'm writing a program in french

    [snip]
    public int compareTo(Object o) {
    TestClass n = (TestClass)o;
    int compData = data.compareTo(n.data);
    return compData ;
    }//end TestClass[snip]
    : if (firstNode.element.compareTo(element)>=0)
    else if (
    e if (
    premierNoeud.obtenirElement().compareTo(element) >=0
    ) {What's up with the >=0 business in your method call?
    Based on what your method expects (an Object) I
    I don't know what you're trying to accomplish there?
    Also, please use code tags.Nevermind, after staring at it I can see the closing paranthesis now.

  • Looking for Java Input Method implementations

    Hi,
    I have developed a Java-based research application for computational linguistics. I'm currently internationalizing this application. I'm looking for FREE implementations of the Java Input Method Framework. Could you please give me a hint?
    Thanks in advance,
    Wolfgang Lezius
    University of Stuttgart, Germany

    http://forum.java.sun.com/thread.jsp?forum=16&thread=270024 contains few useful links.

  • Essential PL/SQL , Java Classes/Methods for working on BLOB

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

Maybe you are looking for

  • When 'PRINT' in ALV report using FM

    Hi I am getting an error when trying to execute and print option in the selection screen. my client system version is 4.6C in the dump  the error at : I am using FM at my report. set_auto_redraw(cl_gui_alf_grid_base) can you provide code for when 'PR

  • FGI0 -Profit Center wise Balance sheet

    HI all In FGI0 we can execute report for the fiscal year 2009. but for 2010 no report is generated. please  guide me whethre we have to execute any carry forward function for this t-code. With regards Jai

  • How to retrive the overwritten SAP Default Configuration

    Hi There, I was trying to enhance the component BT115IT_SLSO to add some new fields into the table view Items. I copied the view configuration to my Z config key but by mistake & added the fields into the default view and saved the changes. Now the d

  • Trying to upgrade broadband option

    Currently on Option 2 40Gb option and tried to update to Unlimited Broadband at £16 p/m but system keeps taking me to Unlimited Broadband Extra at £21 p/m. As the cheaper option is sufficient for my needs I don't see why it will not allow me to updat

  • Adobe Reader 9 cannot turn off bookmark pane

    Every time I open a PDF file in Acrobat Reader 9 I get the Bookmark Pane open on the left. I have gone to Edit > Preferences > Documents > Check the box for, "Restore last view settings when reopening documents" then went to the view menu > navigatio