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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:35:54+00:00 2026-06-09T02:35:54+00:00

JAVA: First off, Thanks so much for taking the time to look at my

  • 0

JAVA: First off, Thanks so much for taking the time to look at my question; your help is EXTREMELY appreciated!

So, the problem is i have a Vector of Objects in Java and each object has a name(String). But, i have tons of objects that are repeated, and the ones that are repeated are always directly after the Object they repeat. Also the number of repeats ranges from 1-10(So frustrating) its completely random.

How would i go about deleting the repeats, I thought about comparing each objects name with the next in the vector and deleting all of the ones that match but that gave me tons of problems. Thank you SO much for your help in advance!

-Dylan

EDIT: Just to make sure you understand the kind of repetition i’m talking about ive added this.

  • Vector
  • —Object1(String name = “hi”) –> Remove This one.
  • —Object2(String name = “hi”)
  • —Object3(string name = “bob”)
  • End Vector
  • Edit 2: add Code

    public class Vector
    {
    public static void main(String args[])
    {
      Person person1 = new Person("jane");
      Person person2 = new Person("jane");
      Person person3 = new Person("bob");
      Person person4 = new Person("shelly");
    
      Vector<Person> vectorObject = new Vector<Person>
      vectorObject.add(person1);
      vectorObject.add(person2);
      vectorObject.add(person3);
      vectorObject.add(person4);
    
     }
    }
    class Person
    {
     String name = null;
     String bDay = null;
     String color = null;
     public Person(String name)
     {
          this.name = name;
         }
    
    
    
    }
    
    • 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-09T02:35:55+00:00Added an answer on June 9, 2026 at 2:35 am

      Well, I don’t know which language are you using, so I will give you an algorithm in JavaScript:

      var newvector=new Array();
      var lastName;
      for(var i=0;i<vector.length;i++){
         if(!lastName || vector[i].name!=lastName){
            lastName=vector[i].name;
            newvector.push(vector[i]);
         }
      }
      

      The problem is that this way a new vector is created, and if the original one is huge maybe you will have memory problems.

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

    Sidebar

    Related Questions

    First off, I'm new to Java, so please be gentle. I have a JFrame
    First off - I haven't had much experience with Java yet, and I'm a
    First off, please accept my apologies if this question is basic, I mainly have
    First off, I don't have any knowledge about java/jquery/ajax or such, but I think
    First off - I'm rather novice at Java so if the question makes no
    First off, I'm coming (back) to Java from C#, so apologies if my terminology
    First off, let me say I am a new to SAX and Java. I
    I've read Head First Java, and I understand how OOP works. Here's my problem:
    I have been programming in Java (my first language) for about six months and
    First off I'm not a Java expert by any stretch, nor am I a

    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.