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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:54:22+00:00 2026-06-15T10:54:22+00:00

I have data in a 2d array, of Object s. I am looking for

  • 0

I have data in a 2d array, of Objects. I am looking for an algorithm which combines duplicate data, but my algorithm loses the ones which are duplicates. Also, it keeps all the rows on the top, so, my data is:

ECE 201 Electrical and Computer Engineering I 2.6666666666666665

BIO 101 Biology I 2.0

CS 101 Computer Science I 3.5

AE 101 Aerospace Engineering I 2.5

BE 101 Biomedical Engineering I 2.0

CS 101 Computer Science I 2.0

CS 102 Computer Science II 3.0

BE 100 Intro Biomedical Engineering 3.6

ECE 200 Intro Electrical and Computer Engineering 3.5

BIO 100 Intro Biology 2.2

CS 101 Computer Science I 3.75

AE 101 Aerospace Engineering I 1.6666666666666667

BE 100 Intro Biomedical Engineering 1.2

but it is filled with nulls. I use the following algorithm:

for (int i = 0; i< finalData.length; i++)
{
  if (finalData[i][1] != null)
  {
    String first = (String)finalData[i][1];
    for (int j = i; j< finalData.length; j++)
    {
      if (finalData[j][1]!= null)
      {
        String second = (String)finalData[j][1];
        if (first.equals(second))
        {
          double one = (double)finalData[i][6];
          double two = (double)finalData[i][6];
          finalData[i][7] = (one + two)/2;
          System.out.println("found!\t" + first + "\t" + second + "\t" +  finalData[i][7]);
        }
      }
    }
  }
}

and my data becomes:

found! ECE 201 ECE 201 2.6666666666666665

found! BIO 101 BIO 101 2.0

found! CS 101 CS 101 3.5

found! CS 101 CS 101 3.5

found! CS 101 CS 101 3.5

found! AE 101 AE 101 2.5

found! AE 101 AE 101 2.5

found! BE 101 BE 101 2.0

found! CS 101 CS 101 2.0

found! CS 101 CS 101 2.0

found! CS 102 CS 102 3.0

found! BE 100 BE 100 3.6

found! BE 100 BE 100 3.6

found! ECE 200 ECE 200 3.5

found! BIO 100 BIO 100 2.2

found! CS 101 CS 101 3.75

found! AE 101 AE 101 1.6666666666666667

found! BE 100 BE 100 1.2

//the found! is just for making sure that it was the right output.

How can I improve this algorithm to produce the desired result?

  • 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-15T10:54:23+00:00Added an answer on June 15, 2026 at 10:54 am

    Instead of writing an algorithm, you can use a set or a hash table.

    Sets are your better choice; they do not allow duplication. You can read more about them here:
    http://docs.oracle.com/javase/tutorial/collections/interfaces/set.html

    Hash tables are a way to implement sets. To use these, you would need to write a hashing function to turn your data into a hash key, then you would use that key to index into the table and store the unhashed value there.

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

Sidebar

Related Questions

I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
I have a long array of data ( n entities). Every object in this
I have a array of two dimensions object[,] data; . I want to convert
Say I have an object-like data record like this: $article = array( 'title' =>
I have this code to sort an array of objects. The data in the
I have a problem related to an array data which fetched from an external
I essentially have a bunch of data objects which map timestamps in milliseconds to
I have an object of which I am looking to get a piece of
I have a webpage with a slickgrid which renders an array of objects on
I have some array data returned from an ajax call consisting of an image

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.