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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:17:38+00:00 2026-05-28T04:17:38+00:00

This post is the continuation of my previous post . Now I have a

  • 0

This post is the continuation of my previous post. Now I have a code that I’d like to compile. The only difference is that now I’m using lists of my own class List<Row> instead of List<Integer[]>. In particular look at hashCode in Row, because it provides a compilation error.

    public class Row {
          private String key;
          private Integer[] values;

          public Row(String k,Integer[] v) {
              this.key = k;
              this.values = v;
          }

          public String getKey() {
              return this.key;
          }

          public Integer[] getValues() {
              return this.values;
          }

          @Override
          public boolean equals(Object obj) {
              if(this == obj)
                  return true;
              if((obj == null) || (obj.getClass() != this.getClass()))
                  return false;
              // object must be Row at this point
              Row row = (Row)obj;
                  return ((key == row.key) && (values == row.values));
          }

          @Override
          public int hashCode () { // HERE I HAVE A PROBLEM. DON'T KNOW HOW TO IMPLEMENT IT
              return this.key;
          }

    }

public class Test {

    public static void main(String[] args) {
        List<Row> allRows = new ArrayList<Row>();
        allRows.add(new Row("0",new Integer[]{1,2,3}));
        allRows.add(new Row("0",new Integer[]{1,2,2}));
        allRows.add(new Row("1",new Integer[]{1,2,3}));
        allRows.add(new Row("2",new Integer[]{1,1,1}));
        allRows.add(new Row("2",new Integer[]{1,1,1}));

List<Row> selectedRows = new ArrayList<Row>();
            selectedRows.add(new Row("0",new Integer[]{1,2,3}));
            selectedRows.add(new Row("2",new Integer[]{1,1,1}));

    System.out.println(allRows);
    System.out.println(selectedRows);
        List<Row> refreshedRows = refreshRows(allRows,selectedRows);
        System.out.println(refreshedRows);

    }

    private static List<Row> refreshRows(List<Row> allRows,List<Row> selectedRows) {
        Set<Row> set1 = new HashSet<Row>();
        Iterator<Row> it = allRows.iterator(); 

        while(it.hasNext()) {
            Row curr = it.next();
            if (!set1.add(curr) && selectedRows.contains(curr)) {
                it.remove();
            }
        }
        return allRows;
    }
}

The result, i.e. refreshedArray, should be equal to:

key = "0", values = {1,2,3}
key = "0", values = {1,2,2};
key = "1", values = {1,2,3};
key = "2", values = {1,1,1};
  • 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-28T04:17:39+00:00Added an answer on May 28, 2026 at 4:17 am

    Try with the following. Despite minor changes, most of the code is generated by Netbeans IDE 7.0:

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Row other = (Row) obj;
        if ((this.key == null) ? (other.key != null) : !this.key.equals(other.key)) {
            return false;
        }
        if (!java.util.Arrays.deepEquals(this.values, other.values)) {
            return false;
        }
        return true;
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 79 * hash + (this.key != null ? this.key.hashCode() : 0);
        hash = 79 * hash + java.util.Arrays.deepHashCode(this.values);
        return hash;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation of a previous post: TPanel color is black no matter
This question is in continuation to my previous post located here . Since there
This post is an continuation of this post I have DlUser Class each object
This question is in continuation of this post , I have tried installing Xerces-C
This is the continuation of the my earlier post Since yesterday I have been
This post concerns only IE. The last line of the following code is causing
In this post I wondered about cleaner code when internationalising an app. that leads
This is somewhat a continuation of this post I've taken the following code and
This post relates to a previous that i posted but the question is different
this is a continuation of the previous post. I need to change some parameters(strings)

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.