Results 1 to 6 of 6

Thread: compareTo()

  1. #1
    Tsiliadoros is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default compareTo()

    Hi everyone, i want to compare two pathnames with compareTo can someone plz upload a quick example using compareTo() method of class file?

  2. #2
    derrickD is offline Member
    Join Date
    Apr 2007
    Location
    USA
    Posts
    50
    Rep Power
    0

    Default

    Are you looking for something like this?
    Java Code:
    public class StringComparator implements Comparator
    {
    
        /*
         * (non-Javadoc)
         * 
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
         */
        public int compare(Object o1, Object o2)
        {
            
            String str1 = (String) o1;
            String str2 = (String) o2;
            if (str1.compareTo(str2) > 0)
            {
                return 1;
            }
    
            if (str1.compareTo(str2) < 0)
            {
                return -1;
            }
    
            else
                return 0;
    
        }
    
    }

  3. #3
    Tsiliadoros is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default compareTo()

    I'm very sorry, what i actually want is .equals()

    i want to compare pathnames of mp3 files and output if they are the same or

    not and i confused with compareTo

    I found what i want sorry for wasting your time:(

  4. #4
    gogoc is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    in that case it will be better if u use .equalsIgnoreCase() because file path with different casing are considered same in windows..
    get new coding problems at CODERWORDS

  5. #5
    Tsiliadoros is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default .equalsIgnoreCase()

    Thanks man this is useful for what i want to do.

  6. #6
    kellaw is offline Member
    Join Date
    Oct 2008
    Posts
    24
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •