Avatar of chima
chima

asked on 

Java ArrayList and if statement

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

ProgrammingJava

Avatar of undefined
Last Comment
chima
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of chima
chima

ASKER

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.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo