Hi everyone, i want to compare two pathnames with compareTo can someone plz upload a quick example using compareTo() method of class file?
Printable View
Hi everyone, i want to compare two pathnames with compareTo can someone plz upload a quick example using compareTo() method of class file?
Are you looking for something like this?
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;
}
}
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:(
in that case it will be better if u use .equalsIgnoreCase() because file path with different casing are considered same in windows..
Thanks man this is useful for what i want to do.
mark thread as solved since its already solved