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 8771759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:52:15+00:00 2026-06-13T17:52:15+00:00

I have a vector of entries. Each entry is an instance of this class:

  • 0

I have a vector of entries. Each entry is an instance of this class:

public class Entry implements Comparable<Entry>{

    private String _key;
    private CustomSet _value;

    [...]

    @Override
    public int compareTo(Entry a) {
        return this._key.compareTo(a._key);
    }
}

The vector is declared as shown below:

Vector<Entry> entries = new Vector<Entry>();

After that, the vector is populated. Then I want to check if certain key is somewhere in the vector. So I do this:

Entry sample = new Entry(key, new CustomSet());
if (entries.contains(sample)) {
    // do something
}

This seems not to work. Why? How can I get it to work?

P.S. CustomSet is another user defined class, irrelevant from my point of view

  • 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-06-13T17:52:17+00:00Added an answer on June 13, 2026 at 5:52 pm

    You have to redefine the equals method in your Entry class, because that’s what contains relies in to determine if an element belongs to a collection, as the docs say:

    Returns true if this vector contains the specified element. More
    formally, returns true if and only if this vector contains at least
    one element e such that (o==null ? e==null : o.equals(e)).

    In this case o is contain‘s method parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector class and I defined the __mul__ method to multiply a
I have the vector d<-1:100 I want to sample k=3 times from this vector
I have a vector where I keep an incrementing data. Normally each element of
I have the vector output = PV_out(:); I am trying to break this down
I have an in-place vector class that's defined like so: template<class T> class svectorbase
I have a class symbol_table that has a vector of objects of another class
I have vector like this: x <- c(20(0.23), 15(0.2), 16(0.09)) and I don't want
I have a std::vector. I assign this vector like vec.assign(20000, 0); Now I have
I have a vector composed of entries such as ZZZ1Z01Z0ZZ0, 1001ZZ0Z00Z0, and so on,
I have a DAG in a JSON format, where each node is an entry:

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.