• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Concatenating Arrays

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Shanker it has helped me.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic