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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:39:00+00:00 2026-06-13T08:39:00+00:00

I would like to know why are my vectors making duplicates? I know i

  • 0

I would like to know why are my vectors making duplicates? I know i can use ArrayList, but this is a test for my blackberry app that only uses vectors at the moment. This is the result i continue to get:

ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl
ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl
ID:3 and Name:Catty and Price:100 and Msg:Catty is a preety girl

Here is the code, testapp.java

package testing;

import java.util.Vector;


public class testapp {
    private static Vector<String> listElements= new Vector<String>();
    private static Vector<String> listName= new Vector<String>();
    private static Vector<Integer> listPrice= new Vector<Integer>();
    private static Vector<String> listDate= new Vector<String>();
    private static Vector<String> listAbstract= new Vector<String>();
    private static Vector<rec> a = new Vector<rec>();
    static rec record = new rec();

    public static void main(String[] args){

        vectorBuilder();
        recordBuilder();
        showElements();

    }

    public static void recordBuilder(){

        try{
            for(int i=0;i<listElements.size();i++){
                record.setId((String) listElements.elementAt(i));
                record.setName((String) listName.elementAt(i));
                record.setDate((String) listDate.elementAt(i));
                record.setPrice(((Integer) listPrice.elementAt(i)).intValue());
                record.setAbstract((String) listAbstract.elementAt(i));
                a.addElement(record);   
            }

        }catch (Exception e){
            System.out.println("Record Builder Error: " + e.getMessage());
        }
    }

    public static void vectorBuilder(){
        //Ben
        listElements.addElement("1");
        listName.addElement("Ben");
        listPrice.addElement(502);
        listDate.addElement("2012-05-12");
        listAbstract.addElement("Ben is a Good Boy");

        //Kesha
        listElements.addElement("2");
        listName.addElement("Kesha");
        listPrice.addElement(367);
        listDate.addElement("2012-02-24");
        listAbstract.addElement("Kesha Works hard in her school work");

        //Catty
        listElements.addElement("3");
        listName.addElement("Catty");
        listPrice.addElement(100);
        listDate.addElement("2012-01-04");
        listAbstract.addElement("Catty is a preety girl");


    }

    public static void showElements(){
        for(int i=0;i<a.size();i++)
        {
            rec r = (rec) a.elementAt(i);
            System.out.println("ID:"+r.getId()+" and Name:"+r.getName()+" and Price:"+r.getPrice()+" and Msg:"+r.getAbstract());
        }

    }
}

Here is the rec.java

package testing;


public class rec {
        String name;
        String id;
        String date;
        String strAbstract;
        int price;


        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }

        public String getDate() {
            return date;
        }
        public void setDate(String date) {
            this.date = date;
        }

        public String getAbstract() {
            return strAbstract;
        }
        public void setAbstract(String strAbstract) {
            this.strAbstract = strAbstract;
        }

        public int getPrice() {
            return price;
        }
        public void setPrice(int price) {
            this.price = price;
        }


}
  • 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-13T08:39:01+00:00Added an answer on June 13, 2026 at 8:39 am

    You need to create new rec while calling recordBuilder. If you don’t create new record same instance will be updated which is why you are getting duplicates.

    for(int i=0;i<listElements.size();i++){
                    rec record = new rec();
                    record.setId((String) listElements.elementAt(i));
                    record.setName((String) listName.elementAt(i));
                    record.setDate((String) listDate.elementAt(i));
                    record.setPrice(((Integer) listPrice.elementAt(i)).intValue());
                    record.setAbstract((String) listAbstract.elementAt(i));
                    a.addElement(record);   
                }
    

    Note: Java naming convention suggests that class name starts with capital letter. Record may be good name than rec.

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

Sidebar

Related Questions

i would like know some reference. I know i can googling it. but prefer
I would like to know that how we can check the available memory in
I would like to know what code to use to convert a double[] array
I would like to know, how can we change the SRC url for IFRAME
I would like to know how. I have looked at this topic , and
I would like to use Bitmaps in my Actionscript games. For me this represents
I would like to use CMAttitude to know the vector normal to the glass
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static
Would like to know how to integarate cruise control with maven? Cruise Control comes

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.