Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-27-2004, 11:19 PM   #1 (permalink)
messageProvider
Registered User
 
Join Date: Aug 2004
Posts: 2
messageProvider is on a distinguished road
Working with ArrayLists

Ok, my problem is this:
Currently i have a arraylist of beans say:

ArrayList list; <-- a list of ItemBean

ItemBean has attributes: PK and Qty.

Given another arraylist of Strings say String[] pK; , i want to look inside the ArrayList list for all element whose ItemBean.getPK() equals each elements of pK. If a match is found then, i would store each ItemBean.getQty() into another Arraylist listQty.

Can you help me with a fast and not so space consuming algorithm?

Thanks in advance.
messageProvider is offline   Reply With Quote
Old 08-28-2004, 05:27 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
I'd sort the ItemBean list based on the PK attribute. This makes binary searches possible. I'd then iterate through the String list, doing a search on the now-sorted ItemBean list. Upon finding a match, remove it from the ItemBean list, populating a new ArrayList.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-29-2004, 05:49 PM   #3 (permalink)
messageProvider
Registered User
 
Join Date: Aug 2004
Posts: 2
messageProvider is on a distinguished road
Quote:
Originally posted by Belisarius
I'd sort the ItemBean list based on the PK attribute. This makes binary searches possible. I'd then iterate through the String list, doing a search on the now-sorted ItemBean list. Upon finding a match, remove it from the ItemBean list, populating a new ArrayList.
Geez Thanks, but it would be nice if you could give me a sample code.
messageProvider is offline   Reply With Quote
Old 08-30-2004, 03:58 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
What part don't you know how to do?
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
working with Multi Dimensional Arrays sde PHP 7 07-11-2004 01:43 PM
Working with an encrypted password in a class. sde Program Design and Methods 3 07-06-2004 01:31 PM
While loop not working alemily PHP 2 06-25-2004 12:07 PM
Script Not Working Ilya020 PHP 1 06-02-2003 06:40 PM
cgi not working on a new script sde PHP 3 05-20-2002 08:29 PM


All times are GMT -8. The time now is 08:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting