Hi there. Can anybody offer me some sound advice in regard to using Vectors. My program renders maps onto a simple GUI. SQL select statements retrieve all the necessary map content and put all these geometry values (polygons, points etc.) into a single Vector object v1. My program takes these geometries from this vector v1 and renders them on to the screen. Each geometry has an associated id in v1 in order to assist referencing that particular geometry. If I perform a query on my map and want to highlight certain points or polygons I send another select statement to the database to retrieve solely the ids of the geometries which form the result of my query. The reason for this is that the coordinates of the geometries already lie in the original vector v1 containing the geometries that were rendered to the screen. The results of my query are inserted into a second vector v2. What I need to do now is to compare the ids in the vectors v1 and v2. v1 will contain hundreds of thousands of elements whilst v2 may contain anything from one to several thousand elements. What I want to do is compare the two vectors v1 and v2 and match every element in v2 with the associated element in v1, i.e. v2 is a subset of v1. Is there a good algortihm for achieving this qiuckly or can anyone give me some useful hints to start off. Cheers Joe
Since you have ids, can you use a Map? For each id in subset, render superset.get(id)? BTW: Vector is on the legacy list. I use a Collections Crib Sheet to help me keep all the new ones straight.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
What I want to do is compare the two vectors v1 and v2 and match every element in v2 with the associated element in v1, i.e. v2 is a subset of v1. Sounds like a Set would be a more natural collection to use for that functionality. Look at the methods retainAll() and containsAll() specified in the Set interface, -- I think this is what you need.