?
Solved

Compare string content in 2 vectors

Posted on 2004-05-02
2
Medium Priority
?
317 Views
Last Modified: 2006-11-17
Hi, exert.

I have 2 vectors with the same elements:

vector1 { ID, name, phone }
vector2 { ID, name, phone }

and 1 vector which conisists of both elementS from vector1 and vector2
vector3 {ID1, ID2, name, phone1, phone2}

I want to find if the element "name" in these vector1 and vector2 are equal
i.e.
if vector 1 contain an element:
ID[1],  name[Grace],  phone[12345]
and vector 2 also contain an element:
ID[4],  name[Grace],  phone[99999]

I will add a new element in vector3, i.e.
ID[1], ID[2], name[Grace],  phone[12345],  phone[99999].

Are there any function in vector can do these in an more effiecient way ?

Thanks

0
Comment
Question by:vincehon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 375 total points
ID: 10974089
for (int i=0; i<3; i++)
{
   vector3.add(vector1.get(i));
   if (vector1.get(i).equals(vector2.get(i)))
   {
      vector3.add(vector2.get(i));
   }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10974162
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 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