We help IT Professionals succeed at work.

Java ArrayList and if statement

chima
chima asked
on
770 Views
Last Modified: 2017-05-03
Hello,
On the first if statement below, I'm trying to branch on a String comparison.  When I print these elements they look the same to my eyes, but the compiler does not agree.  So what am I doing wrong.

while(inCount <= 12){ // 12 is the variable that controls the growth of the Arraylist
			listArrays.add(Arrays.asList(inCount + 0.1));
			
			System.out.println("Current element in list Arrays: " + inCount +" "+ listArrays.get(inCount) + "\n");
			//int count=listArrays.size();
			boolean found = false;
			String comString = listArrays.get(inCount).toString();
			
			comString = comString.substring(1, comString.length() - 1);
			System.out.print("This is the comString: " + comString.toString() + "\n");
			
			
			if(comString.toString() == "7.1"){found = true;
			if(found){
				System.out.println("Bingo! You found it); " + listArrays.get(inCount) + "\n");
				continue;
				}

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Doug, darn I should have known that, because I have used it before.
I'll have other questions, and I do appreciate your help.  I'm working on HashMap now so please stay tuned.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.