Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody!

Im new in java and i have a question about using util.List.

I have 3 values need add to List so im use:

Java
List<Integer> i = new ArrayList<Integer>();

		i.add(140001119);
		i.add(140001106);
		i.add(140001108);


and conditional-AND:
Java
if (i.contains(140001119) && i.contains(140001106) && i.contains(140001108))
			System.out.println("match");


There is problem by using:
Java
if (i.contains(140001119) && i.contains(140001106) && i.contains(140001108))


and Console dont give me "match" words.

So my question is how to use AND with more than 1 value in List?

Thanks in advanced!
Posted
Comments
CPallini 27-Jul-15 3:01am    
Your code outputs 'match' on my Lubuntu box.

1 solution

Advice: copy your condition outside of 'if', cut it in pieces and see what each piece is doing.
Assign pieces to dummy vars?
Some pieces will behave as expected and others will not.
When you that elements are Ok, start to put pieces together and continue to check.

Abuse of debugger.

dummy1= i.contains(140001119);
dummy2= i.contains(140001106);
...
dummy3= i.contains(140001119) && i.contains(140001106);
or
dummy3= dummt1 && dummy2;
 
Share this answer
 
v2
Comments
EADever 27-Jul-15 3:09am    
Can you give a simple code?
Patrice T 27-Jul-15 3:15am    
updated solution
EADever 27-Jul-15 3:19am    
thanks for your solution! but i still need use if for check condition! :(
EADever 27-Jul-15 3:21am    
thanks for your help!
im success with this code:
List<integer> i = new ArrayList<integer>();

i.add(140001119);
i.add(140001106);
i.add(140001108);

boolean a ;
boolean b;
boolean c;

a = i.contains(140001119);
b = i.contains(140001106);
c = i.contains(140001108);


if (a && b && c)
System.out.println("match");

result = match :) thanks brother
Patrice T 27-Jul-15 4:38am    
if you are happy with the answer, you can 'accept' the answer and close the question.

you should also try your code with a,b,c as integers and see what is the result of i.contains(140001119) as integer. you can get a surprise there.
because if it works with boolean, and not in your initial code, it means that boolean changes something.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900