aspose file tools*
The moose likes Beginning Java and the fly likes How can I unite two arrays to one array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I unite two arrays to one array?" Watch "How can I unite two arrays to one array?" New topic
Author

How can I unite two arrays to one array?

qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
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.


Thanks...qingwu<br />When I open my eyes,I see your pretty face.
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
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

Joined: Aug 24, 2001
Posts: 348
qingwu,
I think you can use arraycopy() method from System class to achieve it.


not so smart guy still curious to learn new stuff every now and then
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jun 06, 2002
Posts: 1056
There's also this operation:
list1.addAll(list2);


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
Thanks chi,Jamie,Ron...
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
A little simpler, but not as efficient:

Joe
tomer peretz
Greenhorn

Joined: Aug 03, 2003
Posts: 3
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);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I unite two arrays to one array?