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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:48:18+00:00 2026-05-31T07:48:18+00:00

Hi while developing one of my web application i am storing the user information

  • 0

Hi while developing one of my web application i am storing the user information in to an ArrayList based on sql query executed, it contain duplicate objects how to remove duplicate objects in list , i already tried some method but it still not working.
This Is My Code Correct me where i am wrong

      public ArrayList loadData() throws ClassNotFoundException, SQLException {
    ArrayList userList = new ArrayList();
    String url = "";
    String dbName = "";
    String userName = "";
    String password = "";
    Connection con = null;
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    con = DriverManager.getConnection(url + dbName, userName, password);
    PreparedStatement ps = null;
    try {
        String name;
        String fatherName;
        int Id;
        String filePath;
        int age;
        String address;
        String query = "SELECT NAME,FATHERNAME,AGE,ADDRESS,ID,FILEPATH FROM USER_INFORMATION ,USER_PHOTO WHERE ID=USER_ID";
        ps = con.prepareStatement(query);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            name = rs.getString(1);
            fatherName = rs.getString(2);
            age = rs.getInt(3);
            address = rs.getString(4);
            Id = rs.getInt(5);
            filePath=rs.getString(6);
           /* if(flag)
            {
                prev=Id;
                flag=false;
            }
            else if(Id==prev)
            {
                TEMP=TEMP+";"+filePath;
            }*/
            //PhotoList = PhotoList(Id, con);
            UserData list = new UserData();
            list.setName(name);
            list.setFatherName(fatherName);
            list.setAge(age);
            list.setAddress(address);
            list.setId(Id);
   //       list.setFilePath(filePath);
            userList.add(list);
        }
        ps.close();
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ArrayList al = new ArrayList();
    HashSet hs = new HashSet();
    hs.addAll(userList);
    al.clear();
    al.addAll(hs);
    return al;
}

And My Bean Class contant is

    public class UserData {

private String name;
private String fatherName;
private int Id;
//private String filePath;
private int age;
private String address;
public UserData()
{

}

public UserData(String name, String fatherName,int Id, int age,String address)
{
    this.name = name;
    this.fatherName = fatherName;
    this.Id = Id;
    //this.filePath=filePath;
    this.age=age;
    this.address=address;
}
//GETTER AND SETTER..
  • 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-31T07:48:20+00:00Added an answer on May 31, 2026 at 7:48 am

    If you want a Collection of objects that does not have a specific order and you don’t want duplicates, it’s better for you just to use a Set like for example HashSet, or, if in your set the order is important, the TreeSet.

    Just remember to override the hash and equals methods.

    if you add this to your bean everything should work:

    public int hashCode() {
        return (name + fatherName+ Id + filePath + age + address).hashCode();
    }
    
    public boolean equals(Object obj) {
        return ( hashCode() == obj.hashCode() );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While developing a web based java application I am a bit confused about the
I'm currently developing a web application that has one feature while allows input from
I am developing one web application using asp.net 2005 and Microsoft SQL Server 2008
I'm developing a web application using a cookie to store session information. I've manually
We are developing a web based application on glassfish V3. We have 2 application
How should one go about setting up seed data while developing an nhibernate web
I am developing one web application in that I want to check load time
I'm developing one web application, using PHP eclipse IDE. For an instance i want
While developing a C++ application, I had to use a third-party library which produced
While developing a new query at work I wrote it and profiled it in

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.