Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


muzakir shaik
array list
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


How to get repeate occurence values from database table in java by using arraylist


Advertisement
View Answers

June 1, 2011 at 2:10 PM


import java.sql.*;
import java.util.*;
class GetRepeatedValuesFromDatabase 
{
    public static <T> List getDuplicate(Collection<T> list) {

    final List<T> l = new ArrayList<T>();
    Set<T> set = new HashSet<T>() {
    public boolean add(T e) {
        if (contains(e)) {
            l.add(e);
        }
        return super.add(e);
    }
   };
   for (T t : list){
        set.add(t);
    }
    return l;
}

public static <T> boolean hasDuplicate(Collection<T> list) {
    if(getDuplicate(list).isEmpty())
        return false;
    return true;
}
    public static void main(String[] args) 
    {
        ArrayList<String> list=new ArrayList<String>();

    try{
            Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data");
           String name;
           while(rs.next()){
              list.add(rs.getString("name"));

           }
           if(hasDuplicate(list)){
            List l=getDuplicate(list);
            for(int i=0;i<l.size();i++){
                System.out.println(l.get(i).toString());
            }
        }
    }
    catch(Exception e){}

    }
}


Related Tutorials/Questions & Answers:
array list
array list  How to get repeate occurence values from database table in java by using arraylist
Array List
Array List   Complete the class House and HouseApp below to display class House{ int lotNo; String type; //Bungalow, SemiDetached double price; public House ( int l, String t, double p) { â?¦ } public int theLotN() {
Advertisements
Array List
Array List  Could somebody help me to solve this question. I am glad to hear ideas or answers from everyone. The situation: Complete the class House and HouseApp below to display class House{ int lotNo; String type
array list example
array list example  Array list example   Hello Friend, Please visit the following links: Array List Example1 Array List Example2 Thanks
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
array of students with marks list
array of students with marks list  There are 4 array of numbers or scores as below. They are called marks list and represent the scores individual... across all lists and also the number of students (4 in this case). Marks List 1
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
Convert Array to List
Convert Array to List       In this section, you will learn to convert an Array to List.  Code Description: This program helps you in converting an Array to List. Here we
Convert List to Array
Convert List to Array       Lets see how to convert List to Array.  Code Description... a method Mylist.toArray to convert the List to Array. Here is the code
Shuffling the Element of a List or Array
Shuffling the Element of a List or Array   ... the list or array to prepare each and every element for the operation. In this section, you will learn about shuffling the element of a list or array. Shuffling
Array list in Java - arraylist type error
Array list in Java - arraylist type error  I am using Array list in Java but when i compile i get array list type error. Can anyone please explain what is array list type error and why it occurs
PHP list array keys
array_keys() function returns the keys of the the given array. It returns the keys in the form of array. Example of PHP list Array Keys <?php     $ar1=array("x"=>"x-mas","y"=>"yak","zebra");  
Array list java code - Java Beginners
Array list java code  Create an employee class with an employee id's,name & address. Store some objects of this class in an arraylist. When an employee id is given, display his name & address? Please provide the DETAIL java code
Array list java code - Java Interview Questions
Array list java code  Create an employee class with an employee id's,name & address. Store some objects of this class in an arraylist. When an employee id is given, display his name & address? Please provide the DETAIL java code
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... { List list = new ArrayList(); list.add(new Employee(1, "A","Delhi... = input.nextInt(); for (Employee s : list){ if(id == s.getId
the array list contains similar type of elements or disimilar type of elements
the array list contains similar type of elements or disimilar type of elements  the array list contains similar type of elements or disimilar type of elements
Java ArrayList, Java Array List examples
The Java ArrayList (java.util.ArrayList) is resizable implementation of the List interface. It has support for all the functions present in the List interface... ArrayList list = new ArrayList(); // Adding Element to the ArrayList Object
Real Time code for Array list - Development process
Real Time code for Array list  Hi, Can u give me sample code for Arraylist in real time applications. Thanks PraKash  Hi Friend, Try the following code: import java.util.*; class Student { public
PHP list array
Syntax for PHP List Array void list(var arg1,var arg2,var arg3... the array and assign it to the variables of the list. Example of PHP List Array Code for PHP List Array <?php     $stud = array(1
Spring Wire Array Type To List Element Example
Spring <list> Configuration Element to wire Array type property The list... to set values to the list, are as follows: 1. <value> element can... if you want to set null value. Lets take an example to demonstrate how list
Insert an array list of objects with addAll(ArrayList) method
Insert an array list of objects with addAll(ArrayList) method In this section you will learn to insert an array list of objects to another list...) method.   Learn how to use the addAll method of the List interface. Example
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
List
List  getting values from a form and make a list of them and store them into database
JSP List Size
of the list. The JSP List Size uses array list object to add the elements and finally... of elements in the array. l.size : The method returns the size list... JSP List Size     
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
 

 

 

DMCA.com