Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with BufferedReader

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
How can i identify the given input is null. Here i have a small code. But if i doesn't enter any value also it shows as valid. Heres the code


Somebody please help me out of this.

Thanks & Regards
alexander
 
Rishita Pallavi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change if(input=="") to if(input.equals(""))
It will work.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that readLine can return null, so before calling input.equals you need to check for input being null.
 
Rishita Pallavi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what cases can it return null? Im testing this from my eclipse IDE and not able to simulate a case when it can return a null so that it can fail.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the javadocs:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for replying, i am unable to solve the problem as pallavi said i have used input.equals("") but this is not the only one condition in which it needs to work. If the user gives the input as a space or a tab or 2 or mare spaces or 2 or more tabs it does'nt work. I have also used the trim() method i.e input.trim() also insane. Some body please help me out

heres the code


Thanks and Regards
alexander
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about Remember, Strings are immutable.
 
sandip sangale
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i understood your problem
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot prime what you said really worked thanks again. I have one more question i will start it as new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic