10 Replies Latest reply: Nov 8, 2010 4:18 PM by EJP RSS

    compareToIgnoreCase problem

    3004
      I have to arrays of Address objects the code I have will sort and search the arrays but when I try to ignoreCase the compiler has a fit

      I end up with the following error
      SortSearchUtil.java:63: cannot find symbol
      symbol : method compareToIgnoreCase(java.lang.Comparable)
      location: interface java.lang.Comparable
                                    if(array[searcher].compareToIgnoreCase(array[rs])<0)//based on the type of the object making the call.
                                    ^
      Note: SortSearchUtil.java uses unchecked or unsafe operations.
      Note: Recompile with -Xlint:unchecked for details.
      1 error

      --------My code-----

      public static int binarySearch(Comparable[]array, Comparable target)
           {
           int min, mid, max;
           min = 0;
           max = array.length-1;
           int found = -1;
           do
           {
                mid =(max+min)/2;
                if(array[mid].compareTo(target)<0)
                     min=mid+1;
                else if(array[mid].compareTo(target)>0)
                     max=mid-1;
                else
                     {found = 1;
                     return mid;}
           }while(found == (-1) && min <= max);     
           return found;
           }     


      public static void sortAddresses(Comparable [] array)// class create will own compareto method. geraric
                {
                     int ms, rs, searcher;          
                     Comparable temp;     
                     for(ms = 0; ms<array.length-1; ms++)
                          {
                               rs = ms;
                               for(searcher = ms+1; searcher<array.length;searcher++)
                               {     
                                    if(array[searcher].compareTo(array[rs])<0)//based on the type of the object making the call.
                                    rs = searcher;
                               }
                               temp = array[ms];
                               array[ms] = array[rs];
                               array[rs] = temp;                    
                          }
                     }//end method
        • 1. Re: compareToIgnoreCase problem
          EJP
          Comparable doesn't have that method. String has that method.
          • 2. Re: compareToIgnoreCase problem
            793415
            Please edit your code to use the code tags. ..

            Edit 1:
            No, don't worry about it now. I would not spend time helping cross-posters, even if they used code tags. Thanks again, Darryl.

            Edited by: Andrew Thompson on Nov 8, 2010 1:59 AM
            • 3. Re: compareToIgnoreCase problem
              DarrylBurke
              Cross posted
              http://www.javaprogrammingforums.com/whats-wrong-my-code/5909-comparetoingnore-case-problem.html

              db
              • 4. Re: compareToIgnoreCase problem
                3004
                FYI
                Sorry I "cross posted" whatever. It's called I posted on what I thought was different sites just incase I did not get a response. as for the code tags I would love to use them if I knew how. This is the first time on one of these sites. So to the one that wants to be a dick and not help somebody new just because something might be "cross posted" thanks for nothing.
                • 5. Re: compareToIgnoreCase problem
                  Kayaman
                  808038 wrote:
                  FYI
                  Sorry I "cross posted" whatever. It's called I posted on what I thought was different sites just incase I did not get a response. as for the code tags I would love to use them if I knew how. This is the first time on one of these sites. So to the one that wants to be a dick and not help somebody new just because something might be "cross posted" thanks for nothing.
                  See, we help you people for free and in response we get this. If you can't act civilized here, go somewhere else (although I doubt the more popular Java forums would welcome that sort of behaviour).
                  • 6. Re: compareToIgnoreCase problem
                    3004
                    I really hope once I get good at programing I do not turn in to someone like you that can not remember how it frustrating it is when your just starting out. And then to get crap for "cross posting"...And what help did I get...None... I can figure out that IgnoreCase is something that works with strings and not object. Again thanks for all the help...lol
                    • 7. Re: compareToIgnoreCase problem
                      DarrylBurke
                      808038 wrote:
                      FYI
                      Sorry I "cross posted" whatever. It's called I posted on what I thought was different sites just incase I did not get a response. as for the code tags I would love to use them if I knew how. This is the first time on one of these sites. So to the one that wants to be a dick and not help somebody new just because something might be "cross posted" thanks for nothing.
                      Abuse reported.

                      db
                      • 8. Re: compareToIgnoreCase problem
                        DarrylBurke
                        808038 wrote:
                        I really hope once I get good at programing I do not turn in to someone like you that can not remember how it frustrating it is when your just starting out. And then to get crap for "cross posting"...And what help did I get...None... I can figure out that IgnoreCase is something that works with strings and not object. Again thanks for all the help...lol
                        Abuse reported -- again.

                        db
                        • 9. Re: compareToIgnoreCase problem
                          jduprez
                          Guest wrote:
                          ...
                          Guest ?
                          Jeff, is that you? :o)
                          • 10. Re: compareToIgnoreCase problem
                            EJP
                            And what help did I get
                            You got the help I have you, which I now regret.
                            None
                            That is completely untrue.
                            I can figure out that IgnoreCase is something that works with strings and not object.
                            But you didn't. That was the problem. The only problem. I had to tell you. You can't even acknowledge that, leaving aside your ill manners.
                            Again thanks for all the help...lol
                            I won't be making that mistake again.