|
-
Text input
I'm at a loss here.
I'm tying to read text from standard input and then play with the string
in an if statement, but for some reason, the if statement won't take it.
Here's the snippet of code:
/*********************/
public static void main(String[] args) throws IOException {
BufferedReader stdin = new BufferedReader
(new InputStreamReader(System.in));
while(true){
String selection = stdin.readLine();
if( selection == "a") {
System.out.println("blah");
}
}
}
/***********************/
"Blah" is never printed out even if "selection" really does equal "a".
It DOES work though, if I set "selection" to "a" before the if statement.
The if statement acts as if "selection" is null, but when I change the condition
to, "if( selection != null)", then it is accepted and prints out "blah" like
it's supposed to.
It also works if I use numeric values rather than strings.
Anyone know what the problem is?
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks