Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Searching in Arrays

0 views
Skip to first unread message

makzan via JavaKB.com

unread,
Jul 30, 2005, 9:20:44 AM7/30/05
to

Hi,

I'm fairly new to Java and I'm trying to make a program that will store
certain objects and then list them depending on their features. I hope this
makes sense and I hope I get the terminology right!

For example,
I want to store instances of "people" and they need to have true or false to
the following questions.
Are they male?
Are they tall?
Do they have brown eyes?

Then I want to be able to list all of the people who are not male, all that
are tall and all that have brown eyes.
What is the best way to store them and how can I return the people with brown
eyes, for example?

Andrew Thompson

unread,
Jul 30, 2005, 9:33:22 AM7/30/05
to
On Sat, 30 Jul 2005 13:20:44 GMT, makzan via JavaKB.com wrote:

> I'm fairly new to Java ..

Just a quick note that those new to Java are best helped
on a usenet newsgroup called comp.lang.java.help[1], it will
appear as 'First Aid' through the JavaKB[2] web interface.

[1] <http://www.physci.org/codes/javafaq.jsp#cljh>
[2] <http://www.physci.org/codes/javafaq.jsp#usenet>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Secreted by the Comedy Bee

Malte

unread,
Jul 30, 2005, 9:41:35 AM7/30/05
to
If this is not a school assignment and if the application is not very
minor, I'd consider using SQL.

makzan via JavaKB.com

unread,
Jul 30, 2005, 10:11:16 AM7/30/05
to

It's a uni project, so don't give me the exact code!!!
I've decided to add the people to different HashSets depending on the values
entered seeing as there are not many values. Then I can just list a specific
HashSet, or all of them at the same time if needed.
However, if there is a better way, I'd like to know!!!
Thank you though

Malte wrote:
>> Hi,
>>
>[quoted text clipped - 13 lines]

Dimitri Maziuk

unread,
Jul 30, 2005, 12:49:44 PM7/30/05
to
makzan via JavaKB.com sez:
>
> It's a uni project, so don't give me the exact code!!!
> I've decided to add the people to different HashSets depending on the values
> entered seeing as there are not many values. Then I can just list a specific
> HashSet, or all of them at the same time if needed.
> However, if there is a better way, I'd like to know!!!

No, you're basically creating DB indexes (each HashSet is an index) and
there's no way around it. If your objects have a large number of attributes
and/or you don't know in advance what attributes you're going to search on,
you're better off with an SQL database (e.g. HSQLDB). With small number of
attributes you'll use hashes. With a single attribute you could use sorted
list.

Another thing SQL makes easier is finding intersections, unions, etc. of
subsets: e.g. all tall people with brown eyes and dark or red hair.

Dima
--
Riding roughshod over some little used trifle like the English language is not a
big deal to an important technology innovator like Microsoft. They did just that
by naming a major project dot-Net (".Net"). Before that, a period followed by a
capital letter was used to mark a sentence boundary. --T. Gottfried, RISKS 21.91

Roedy Green

unread,
Jul 30, 2005, 9:41:32 PM7/30/05
to
On Sat, 30 Jul 2005 13:20:44 GMT, "makzan via JavaKB.com"
<fo...@JavaKB.com> wrote or quoted :

>Then I want to be able to list all of the people who are not male, all that
>are tall and all that have brown eyes.
>What is the best way to store them and how can I return the people with brown
>eyes, for example?

look at BitSet. In Java 5, loot at EnumSet.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes

Thomas Weidenfeller

unread,
Aug 1, 2005, 3:48:40 AM8/1/05
to
Andrew Thompson wrote:
> Just a quick note that those new to Java are best helped
> on a usenet newsgroup called comp.lang.java.help[1], it will
> appear as 'First Aid' through the JavaKB[2] web interface.

You might want to add that JavaKB not only renames Usenet groups, but
also doesn't tell people that these groups are indeed Usenet groups, and
not a JavaKB invention. And, JavaKB strips of information not only from
the message header, but also the message body. The later is highly
questionable behavior.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Andrew Thompson

unread,
Aug 1, 2005, 9:48:42 PM8/1/05
to
On Mon, 01 Aug 2005 09:48:40 +0200, Thomas Weidenfeller wrote:

> Andrew Thompson wrote:
>> Just a quick note that those new to Java are best helped
>> on a usenet newsgroup called comp.lang.java.help[1], it will
>> appear as 'First Aid' through the JavaKB[2] web interface.
>
> You might want to add that JavaKB not only renames Usenet groups, but
> also doesn't tell people that these groups are indeed Usenet groups, and
> not a JavaKB invention. And, JavaKB strips of information not only from
> the message header, but also the message body. The later is highly
> questionable behavior.

'strips information .. from message body'?
Can you provide a link that demonstrates?

I 'crash banged' around JavaKB early on, looking for
any indication that they edited or mangled messages,
but could find none.

Beats A Hard Kick In The Face

Thomas Weidenfeller

unread,
Aug 2, 2005, 3:27:37 AM8/2/05
to
Andrew Thompson wrote:
> 'strips information .. from message body'?
> Can you provide a link that demonstrates?

Compare

http://www.javakb.com/Uwe/Forum.aspx/java-programmer/19684/Searching-in-Arrays#loa39relhhua.7ky9exb73f7s$.dlg@40tude.net

to

http://groups.google.com/group/comp.lang.java.programmer/msg/0e931b0987671bad?dmode=source

Do you note the missing attributions "... xyz wrote ..."?

Andrew Thompson

unread,
Aug 2, 2005, 3:59:16 AM8/2/05
to
On Tue, 02 Aug 2005 09:27:37 +0200, Thomas Weidenfeller wrote:

> Andrew Thompson wrote:
>> 'strips information .. from message body'?
>> Can you provide a link that demonstrates?

> Do you note the missing attributions "... xyz wrote ..."?

Got it. I will make a note of it when I get a moment,
but I must admit it is not as serious as I thought.

Having dealt with groups beta ..
- hiding sigs automatically,
- encouraging top-posting by hiding 'quoted text' by default, and
- losing around 40% of old posts,
..and dealing with other web interfaces that actually
*screened* posts out of their own site - specifically
posts slagging them...
..It just does not seem that world shattering.

Maybe they are just wearing me down. I feel we need
to accept that some aspects of interaction though
Usenet Newsgroups *will* change as a result of the
latest (last year or so) changes to the web interfaces.

Deciphered From Crop Circles

0 new messages