Removing duplicate values from array list ( elements added from mysql) but not working


`Preformatted text````

         ArrayList<String> stationlist=new ArrayList();//array list declared
        ArrayList<String> correcttrainlist=new ArrayList();// another list
        ArrayList<String>modellist=new ArrayList();    
        // modellist for add in combobox
        try ///////////////
        // sql connectivity starts here
         Class.forName("com.mysql.jdbc.Driver");// sql connectivity                                               Connection con=DriverManager.getConnection                                    ("jdbc:mysql:///viru","root","");
           String Query=" Select  * from trains"; // fetching from trains table
           PreparedStatement ps=con.prepareStatement(Query);
           ResultSet rs=ps.executeQuery();// result set object 
              // fetching stations from mysql  
              stationlist.add(rs.getString("stations"));//  array list

               Set<String> stationswithoutdup= new HashSet<String>(stationlist); // string type
    // hashset used for removing duplicate values from array list 

              stationlist.clear();// clear list

              stationlist.addAll(stationswithoutdup);// add set to list
              stationlist=new ArrayList<String>(Arrays.asList(stations.split(",")));
    // splitting a column by comma (,)


    // str1 and  str2 used for from station and to station textfield input

// fetching trainname and trainno which matched to user inputs

      Set<String> correctlistwithoutdup= new HashSet<String>(correcttrainlist);

      correcttrainlist.clear();// clear previous correct list
![repeat trains|320x183](upload://68TwWq6car4PVgto9862ZvNXYCr.PNG)
    // adding the trainame and trainno to combobox to display in frame
                 for(int i=0;i<correcttrainlist.size();i++)     
           String [] resultmodel=modellist.toArray(new String [modellist.size()]); 
   // adding required values to jcombobox for display
           DefaultComboBoxModel obj=new DefaultComboBoxModel(resultmodel);


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.