File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes [Help] Grouping of array elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "[Help] Grouping of array elements" Watch "[Help] Grouping of array elements" New topic

[Help] Grouping of array elements

Jake Lee

Joined: Apr 02, 2002
Posts: 18
I have an array, say arrCode[] and there two fields under that: key, value.
Based on the values of keys, group all values into groups of same key values. and the result should be groups of arrays of same keys with corresponding values. Anyone has some sample code to accomplish this?
Thanks a lot.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What have you done so far? Please post some code snippits that illustrate the work you have put into this program. Also, explain what problems you have encountered, and indicate the line number where you think something is wrong.
Keep coding!

Java API Documentation
The Java Tutorial
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Sounds like to me this is just a O(n) problem.
Jake Lee

Joined: Apr 02, 2002
Posts: 18
Here you go:
inside arr1:
based on the values of ids in arr1, sort out unique ids and create same structure of the above hierarchy by putting arr2 elements into one arr2 when ids are same. Basically to eliminate duplicate ids...and regroup their children.
Any thoughts??
[ January 27, 2003: Message edited by: Jake Lee ]
I agree. Here's the link:
subject: [Help] Grouping of array elements
It's not a secret anymore!