Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

List Find

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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