Simpler way to filter

L

laredotornado

Hi,

I'm using Java 1.5. I have a Vector of objects, all of type
"MyProperty". What I want is to filter the vector and keep the
elements whose "MyProperty.getName.equals(someString)". Is there any
easier way of doing this rather than iterating over the Vector,
looking at each element, then adding that element to the new, filtered
vector depending on whether it has met the conditions?

I'm thinking that's the easiest way but I've been wrong before, - Dave
 
A

Arne Vajhøj

Knute said:
The only significant difference between Vector and ArrayList is the fact
that Vector is synchronized. If you need simple synchronization on your
ArrayList there is no difference.

Collections.synchronizedList is the pondered way of enabling that.
The difference certainly doesn't
justify the bandwidth utilized to admonish those Vector users.

I would not retrieve the benefits of teaching impenetrable practice
to not only the those that posted but also the x100 that just
read.

Debbie



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Even today I am willing to volunteer to do the dirty work for
Israel, to kill as many Arabs as necessary, to deport them,
to expel and burn them, to have everyone hate us, to pull
the rug from underneath the feet of the Diaspora Jews, so
that they will be forced to run to us crying.

Even if it means blowing up one or two synagogues here and there,
I don’t care."

--- Ariel Sharon, Prime Minister of Israel 2001-2006,
daily Davar, 1982-12-17.
 
M

Msj121

Hi,

I'm using Java 1.5. I have a Vector of objects, all of type
"MyProperty". What I want is to filter the vector and keep the
elements whose "MyProperty.getName.equals(someString)". Is there any
easier way of doing this rather than iterating over the Vector,
looking at each element, then adding that element to the new, filtered
vector depending on whether it has met the conditions?

I'm thinking that's the easiest way but I've been wrong before, - Dave

Hmmm, interesting question. If this is a major component and the
Vector is large - perhaps a hashmap (or table) of named properties, so
that they are split (O(1)) instead of (0(n)). If this is minor
compared to having one table - then you could try sorting them to have
quicker responses.

Otherwise, it might seem like iterating is the simple way to do it.

MSJ121
 
D

Daniele Futtorovic

Hi,

I'm using Java 1.5. I have a Vector of objects,

*BZZT*. The only possible reason you could justifiably use a
java.util.Vector would be if you coded with a JSE version prior to 1.2.
all of type
"MyProperty". What I want is to filter the vector and keep the
elements whose "MyProperty.getName.equals(someString)". Is there any
easier way of doing this rather than iterating over the Vector,
looking at each element, then adding that element to the new, filtered
vector depending on whether it has met the conditions?

No.

Removing elements is slower in every but the most trivial cases.
 
K

Knute Johnson

Daniele said:
*BZZT*. The only possible reason you could justifiably use a
java.util.Vector would be if you coded with a JSE version prior to 1.2.

The only significant difference between Vector and ArrayList is the fact
that Vector is synchronized. If you need simple synchronization on your
ArrayList there is no difference. The difference certainly doesn't
justify the bandwidth utilized to admonish those Vector users.
 
D

Daniele Futtorovic

The only significant difference between Vector and ArrayList is the fact
that Vector is synchronized. If you need simple synchronization on your
ArrayList there is no difference. The difference certainly doesn't
justify the bandwidth utilized to admonish those Vector users.

Maybe that admonition reflects exasperation over how long that Vector
stuff sticks among new Java programmers, seeing as it is an as good as
deprecated API bit. Many (global rather than local) mistakes, or cases
of design less good than it might be, arise from its usage. The
Collections Framework is a whole into which Vector doesn't fit seamlessly.

I understand your reaction though. I didn't mean to bash. My own, and
possibly others', assertive tone on this might be due to a shunning away
from getting into actual arguments over it.
 
A

Arne Vajhøj

Knute said:
The only significant difference between Vector and ArrayList is the fact
that Vector is synchronized. If you need simple synchronization on your
ArrayList there is no difference.

Collections.synchronizedList is the recommended way of achieving that.
The difference certainly doesn't
justify the bandwidth utilized to admonish those Vector users.

I would not underestimate the benefits of teaching good practice
to not only the those that posted but also the x100 that just
read.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top