File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Concatenating Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Concatenating Arrays" Watch "Concatenating Arrays" New topic

Concatenating Arrays

Vijay Mitra

Joined: Jul 06, 2001
Posts: 11
Is there any way to concatenate 2 String (or any type) of arrays.
I have got 2 arrays , which I want to join from a specified index of each and assign the results into a new one. Currently I'm using a simple for loop, but that seems to take a considerable time.
Ex: String[] a = new String[1000];
String[] b = {"a" , "b"};
String[] c = new String[1002];
c[0] = b[0];c[1] = b[1];
for (int i=0;i<1000;i++) c[i+2] = a[i];
i.e the first 2 positions in c has to be the array b and rest of them from array a.
Any suggestions using class Array or Collections or any other which would make it faster.
Thanx .
San Su
Ranch Hand

Joined: Jul 06, 2001
Posts: 313

You can use System.arraycopy() method.
Here is the method signature..
public static native void arraycopy(Object src,
int src_position,
Object dst,
int dst_position,
int length)
Vijay Mitra

Joined: Jul 06, 2001
Posts: 11
Thank you Shanker it has helped me.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Please use the proper forum.
I am moving this to the Java in General (Intermediate)
forum. PLease feel free to continue the discussions
in that forum.
Thanks for your cooperation.
- satya

Take a Minute, Donate an Hour, Change a Life
I agree. Here's the link:
subject: Concatenating Arrays
It's not a secret anymore!