aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "[Help] Grouping of array elements" Watch "[Help] Grouping of array elements" New topic
Author

[Help] Grouping of array elements

Jake Lee
Greenhorn

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.
J-
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!
Layne


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
Greenhorn

Joined: Apr 02, 2002
Posts: 18
Here you go:
arr1[]
arr1[].id
arr1[].value
inside arr1:
arr2[].itemNo
arr2[].value
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??
Jake
[ January 27, 2003: Message edited by: Jake Lee ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Help] Grouping of array elements