• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I unite two arrays to one array?

 
qingwu wang
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,I want to know how many methods can resolve it.
I try to use loop to do it,but I think it is not a good thing.
 
qingwu wang
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I implement it as following:

so I got it.but I donnt know if I should do so.
[ July 28, 2003: Message edited by: qingwu wang ]
 
chi Lin
Ranch Hand
Posts: 348
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
qingwu,
I think you can use arraycopy() method from System class to achieve it.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write a merge method ( or I can ):

or you could utilize the List interface:

Hope that helps,
Jamie
[ July 29, 2003: Message edited by: Jamie Robertson ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also this operation:
list1.addAll(list2);
 
qingwu wang
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks chi,Jamie,Ron...
 
Joe Pluta
Ranch Hand
Posts: 1376
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little simpler, but not as efficient:

Joe
 
tomer peretz
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object[] obj3a = new Object[obj1.length + obj2.length];
System.arraycopy(obj1, 0, obj3a, 0, obj1.length);
System.arraycopy(obj2, 0, obj3a, obj1.length, obj2.length);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic