Solved

List Find

Posted on 2002-06-24
5
174 Views
Last Modified: 2010-03-31
Hi Everyone,

  Ok, so I am pulling a String from a database field, that is a comma-delminated list.  It's a list of zip codes... so for instance "00101, 44303, 55101".  I need a way to find if a zip is in that list.

So with the above list, if I searched for 44303, it would come back true, but if I search the above list for 55555, it would come back false.

  I just need to know how to search through that list.
Like in ColdFusion you would just go:

ListFind(list, valueToSearchFor, delimeter)

Something along the same lines as that.

Any ideas?

Thanks
Ben
0
Comment
Question by:bptacek
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 7105170
how about indexOf ?

String zips = "00101, 44303, 55101";

if ( zips.indexOf("44303,") >= 0 )
  return true;
else
  return false;
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7105176
so, a function to do this:

boolean zipExists(String zipToFind, String zipList)
{
   if ( zipToFind==null || zipList==null )
      return false;

   if ( zipList.indexOf(zipToFind+",") >= 0 )
      return true;
   else
      return false;
}

boolean rc = zipExists( "44303", "90210, 44303, "54321" );
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
ID: 7105178
hmm, maybe you don't need to look for the comma (in case it is at the end of the list)

if ( zipList.indexOf(zipToFind) >= 0 )
0
 

Author Comment

by:bptacek
ID: 7105207
Ok, I am checking it out right now.

ben
0
 

Author Comment

by:bptacek
ID: 7105236
That will do it sir! Thanks, here's your points.

Ben
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now