This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Merge array's in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Merge array Watch "Merge array New topic
Author

Merge array's in java?

Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
HI all,
I am stuck in a situation where i need to merge the contents of two long[].
Heres the example for my requirement

I know the routine way of running for loops to copy the contents from one array to other...
IS THERE ANY OTHER EFFICIENT WAY OF DOING THIS.
Regards
Reshma


SCJP 1.4, SCWCD 1.4
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Believe it or not System has a method to help you with that. arraycopy (Yes, naming convention doesn't follow Sun's standard imagine that :roll: )
:roll:
[ August 27, 2003: Message edited by: Carl Trusiak ]

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
Check into System.arrayCopy()
You should be able to create a third array with a length equal to the sum of the other two. Then just use this method to place the elements from the first two into the third array.
hth
-EDIT----------------------------
DOH! Carl beat me to it...
---------------------------------
[ August 27, 2003: Message edited by: Chris Shepherd ]
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
Hi Chris .
Thanks a ton for the help, it was extremely helpful to me. For a while i was in java.util park looking for this functionality :roll:
Reshma
[ August 27, 2003: Message edited by: Reshma Pai ]
 
Consider Paul's rocket mass heater.
 
subject: Merge array's in java?
 
Similar Threads
Wrapper class
How many String objects ... ?!
Standalone JS File
Iterating a List Using JSTL
Merging Multiple Lists