Solved

List Find

Posted on 2002-06-24
5
179 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 33
Java - Why doesn't this JFrame work 3 59
eclipse java  build path 6 56
reverse digits of a number using for loop 5 40
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

770 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