|
|
Re: incompatiple types how to sort it, help pls
|
Posted: Nov 25, 2004 12:14 AM
|
|
Your have 2 essentional errors:
1.
alldrives[k] is a File object.
skipDrive(skdrive) delivers a String object. == will never work this way. To solve this problem, you have to compare the String with:
alldrives[k].getName() or
alldrives[k].getPath() Since getName and getPath will deliver a valid drive name and not just the drive letter, you will have to extract the drive letter from the String. substring (0,1) should do the job.
2. String s1 = "abcd"; String s2 = "abcd"; boolean b = s1 == s2; b will allways be false. Why? s1==s2 compares the Object, not it's content. These are 2 different objetcs with the same content. The solution is:
s1.equals(s2)
3. (not essential) You should use the Java naming convention. AllRoots[] should be called allRoots[], because it's not a class, but a variable.
4. Want to compare the drive letters directly? Use the datatype char (not Character). Since it is a primitive type (like int, double, float, boolean, ...) instead of an Object, the content get's compared.
How to?
File drive = ...; char nameChar f.getPath().charAt(0);
Change your skipDrive Method to public static char skipDrive and return the char'A'
|
|