Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:27:17+00:00 2026-05-31T01:27:17+00:00

Suppose, I have a vector with following values in it id = 100 latitude

  • 0

Suppose, I have a vector with following values in it

id = 100
latitude = 2 .33
longitude = 4.55

id = 200
latitude = 1.00
longitude = 3.00

id = 300
latitude = 2.33
longitude = 4.55 

and I have following variables

int item = 10;
double x = 2.33;
double y = 4.55 

1.) Now, I want to compare the values of 2 variables (x,y) with that of (latitude,Longitude) in the vector.

2.) If (x,y) value is equal to (latitude,Longitude) then I add value of item variable to the vector

My logic to achieve it is as follows

Vector al;
int size = al.size() //need to adjust the size as and when i add/remove items from al

for(int i=0;i<sz-1;i++)
{
  if(al.get(i).getClass().equals(Double.TYPE)) //Need to ignore id in Vector

   if(a.get(i)==x & a.get(i+1)==y)
    {
      //add the sensor id at i-2 and adjust the size of vector
    }
   else {
          //remove the items 200,1.00,3.00
          // adjust the size of vector
        }

But the above code is not giving me expected result.Can anybody provide me with working code to get the final output as follows

10,100,2.33,4.55
10,300,2.33,4.55

Note that contents 200,1.00,3.00 are not present in the expected o/p, ‘coz value of (x,y) does not match with (latitude, longitude)

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:27:19+00:00Added an answer on May 31, 2026 at 1:27 am

    This is the way to solve the above problem. I am including code snippet

    public void manip() {
    
        System.out.println("ArratList (Before) :" + Array);
        int sz = Array.size();
        for (int i = 0; i < sz - 1; i++) {
            Object o = Array.get(i);
            if (o instanceof Double) {
                if (Array.get(i).equals(x) & Array.get(i + 1).equals(y)) {
                    if (i == 1) {
    
                        Array.add(0, item);
                    } else {
    
                        Array.add(i - 1, item);
                    }
                    i = i + 3;
                } else {
                    Array.remove(i - 1);
                    Array.remove(i - 1);
                    Array.remove(i - 1);
                    i = i - 1;
                }
                sz = Array.size();
            }
        }
    
        System.out.println("ArratList (After) :" + Array);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have a std::vector<int> v //and ... for(int i =0;i<100;++i) v.push_back(i); now i
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
Suppose I have the following function: void foo(std::vector<int> vec, int n); If I call
Suppose I have a vector<int> myvec and I want to loop through all of
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
Suppose I have the following vector: x <- c(8, 6, 9, 9, 7, 3,
Suppose I have the following files: lib/A.h #ifndef A_H #define A_H #include <vector> class
Suppose I have a class similar to the following: #include <vector> class element {
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int
suppose I have this vector vector<Object> m; and then I have the following assignments:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.