-
August 26th, 2004, 10:46 PM
#1
Member
Java syntax question
i am trying to check a string to see if it is equal to "w" but it wont work.
public File(String FileName, String mode){
System.out.println(mode);
if(mode == "w"){
System.out.println(mode);
OpenWrite(FileName) ;
}
else{
System.out.println("not w");
OpenRead(FileName) ;
}
}
now i know by testing that "w" prints before the equilty statement, but then "not w" prints next, any help would be great.
-
August 27th, 2004, 05:24 AM
#2
lol
http://java.sun.com/j2se/1.4.2/docs/...ng/String.html
public File(String FileName, String mode){
System.out.println(mode);
if(mode.equals("w")){
System.out.println(mode);
OpenWrite(FileName) ;
}
else{
System.out.println("not w");
OpenRead(FileName) ;
}
}
Strings are objects, you can only use == with primitive data types like int, double and boolean. If you're taking a class you will learn all about comparing objects, should be good for you . Peace.
-
August 28th, 2004, 01:30 AM
#3
Actually h3r3tic, you are technically incorrect in saying that you can only use == with primitive data types. You "can" use == to compare objects, but with objects, == evaluates whether or not two objects are exactly the same; (as in same memory address, etc.) at least that's what I believe is the case.
But hey, that was a pointless comment from me...just being pedantic I figure if I write this reply I might actually be able to get to sleep.
ac
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|