By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,885 Members | 720 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,885 IT Pros & Developers. It's quick & easy.

String Not equal Array element.

P: 1
Hi!!

How do I write the if condition to say user string input does not equal the values inside the array. Your response will be appreciated.
Aug 20 '19 #1
Share this Question
Share on Google+
3 Replies

dev7060
Expert 100+
P: 311
Expand|Select|Wrap|Line Numbers
  1. if(!str1.equals(str2)){
  2.   ...
  3. }
  4.  
equals() method compares two strings and if the content of both strings is the same, it returns true. Not operator is used according to the need.
Aug 20 '19 #2

P: 32
You can use contains method to achieve your requirement :

Expand|Select|Wrap|Line Numbers
  1. if(!Arrays.asList(arr).contains(user_string)){
  2.     ...
  3. }
In Following code, contains method returns false if it contains user_string in array else it will return true
1 Week Ago #3

dev7060
Expert 100+
P: 311
My reply was incomplete. The code should be inside a loop to traverse through all the values.
1 Week Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.