File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concatenating Arrays

 
Vijay Mitra
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 313
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Shanker it has helped me.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic