File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes .equals (any value) ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ".equals (any value) ?" Watch ".equals (any value) ?" New topic
Author

.equals (any value) ?

abhiavi kumar
Greenhorn

Joined: Mar 13, 2013
Posts: 20
Hello guys, I'm a beginner, and got this project work that needs to be done.

Anyway, I am familiar with .equals(),

the current code used is

if cutval.equals("cus") {}

else

if cutval.equals("man") {}

I hope you understand what I'm trying to. I want this .equals condition to take any value, for example, I thought this would work, but it didn't.

cutval.equals("") and also cutval.equals("*")

I can post the entire code if you want, I'm just a beginner. Help would be greatly appreciated.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Welcome to the Ranch!

If cutval is allowed to be any value, then why do you need to do the comparison at all? The result will always be true if it should match any value! Maybe you have a series of if ... else if ... statements and you want to do something whenever cutval is anything else than what you already tested? If that's the case, just add an else statement at the end:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
abhiavi kumar
Greenhorn

Joined: Mar 13, 2013
Posts: 20
I know it is as simple as that but perhaps my program is a lot more complicated.



Here's my entire code, every time I remove either && cutval.equals("j")) or && cutval.equals("man")) (Highlighted red in code), I get an error, my web browser says something along the lines of "Remove token from line 12" or something.... if i do that other errors popup.

I have no idea, these methods are too complicated to me, any help would be appreciated again.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

If you remove && cutval.equals("j")) you ofcourse have to make sure that the parentheses are balanced.

If you remove that and your if-statement looks like: if(option.equalsIgnoreCase("user")

then you are missing a closing parenthesis.
abhiavi kumar
Greenhorn

Joined: Mar 13, 2013
Posts: 20
I guess I should also provide this information as well, I'm using Oracle as backend. Originally, the application generated an automatically generated password which is either (J+(something) or (Man+(something)). Customers get a (J+something) password and manufacturers get a (Man+something) password

I modified the program, I put in a textbox through which an user can provide his own password (rather than the ones automatically generated).

See for example cutval.equals("J") only works for one of the users I created, whose password starts with "J", "Jingle"

and

all the passwords that start with "Man" work as well.

So, I thought why not let the .equals take any value, as there is also an "User_option" which decides if the user is a customer or manufactuer?

abhiavi kumar
Greenhorn

Joined: Mar 13, 2013
Posts: 20
Jesper de Jong wrote:If you remove && cutval.equals("j")) you ofcourse have to make sure that the parentheses are balanced.

If you remove that and your if-statement looks like: if(option.equalsIgnoreCase("user")

then you are missing a closing parenthesis.


Hot diggity, you solved my problem.... you are a life saver.... thank you.

That was a total noob's mistake.... thank you again. Now I can safely do my thing with this application...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .equals (any value) ?
 
Similar Threads
String to variable - urgent!
Using an Iterator to filter an arbitrary Collection
How to: Change af:outputText according to Click of an af:selectBooleanCheckbox
while loop
How to: Change af:outputText according to Click of an af:selectBooleanCheckbox