[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to combine 3 vector into 1 Vector

Posted on 2006-04-23
10
Medium Priority
?
258 Views
Last Modified: 2008-03-10
I have 3 vectors
VectorA ("a","b","c")
VectorB ("d","e","f")
VectorC ("g","h","i")
I want to use VectorD to contains all the data from VectorA, VectorB, VectorC
so VectorD will contains
("a","b","c","d","e","f","g","h","i")
How to do it?


(I cannot simply do a
VectorD.add(VectorA)
VectorD.add(VectorB)
VectorD.add(VectorC)
Since then it will contains
(VectorA,VectorB,VectorC)

Also, loop through VectorA, VectorB, VectorC to dump all the data to Vector is a workable way, however in reality, each vector may contain hundred of data, and there are 60 over those vectors and performance is a concern.

So, hopefully there is a way to do it without affecting performance too much)
0
Comment
Question by:william007
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1600 total points
ID: 16519423
a.addAll(b);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16519429
In your case,

VectorD.addAll(VectorA);
VectorD.addAll(VectorB);
VectorD.addAll(VectorC);
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 400 total points
ID: 16519433
>> however in reality, each vector may contain hundred of data, and there are 60 over those vectors and performance is a concern

Internally, that's what addAll () will also do, I don't think there is an escape from that.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16519803
as CHEJ said addAll will do the job.

And when it comes to performance if the program which you are writing doesn't use threads i would Suggest you to go with ArrayList then vetors (but they are not thread safe yet have better performance).Check out

http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16520040
If you want to get the best performance try FastList:

http://javolution.org/
0
 
LVL 92

Expert Comment

by:objects
ID: 16521229
> Also, loop through VectorA, VectorB, VectorC to dump all the data to Vector is a workable way

Thats exactly what addAll() will do :)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16522366
>> http://javolution.org/

Interesting :) have you used it CEHJ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16523109
>>Interesting :) have you used it CEHJ?

Yes, if only 'because it's there' in software i'm using anyway
0
 
LVL 9

Author Comment

by:william007
ID: 16531069
Thanks:-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16533344
:-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question