Java ArrayList

Java ArrayList

How to declare unique ArrayList ?
View Answers

October 30, 2010 at 4:01 PM

Hi,

Here is the program of Unique ArrayList.

import java.util.ArrayList;

public class ArrayListExample {
public static void main(String[] args) {
        ArrayList<Object>  arrList = new ArrayList<Object>();
        String str1 = new String("Bharat");
        String str2 = new String("Gyan");
        String str4 = new String("Bikrant");
        Integer i = new Integer(22);
        System.out.println("Size of ArrayList is :" + arrList.size());
        System.out.println("Element in array list : " + arrList);
        arrList.add(str1);
        arrList.add(str2);
        arrList.add(i);
        arrList.add(str4);
        System.out.println("Size of ArrayList is :" + arrList.size());
        System.out.println("Element in array list : " + arrList);
        System.out.println("Object at index 1 : " + arrList.get(1));
        arrList.clear();
        System.out.println("Size of ArrayList after clear method :"
                        + arrList.size());
        System.out.println("Element in array list after clear method : "
                        + arrList);
        }
}

May 5, 2011 at 12:23 AM

Actually i donot understand how it is unique can u explain.


June 21, 2011 at 1:39 PM

What do you mean by unique here ? Can you please clarify if you are looking for some basicjava arraylist stuff then check here ? would be able to help more if you clarify your question.


March 19, 2012 at 4:20 PM

Override the add methods in ArrayList as follows.

public class UniqueChildAList extends ArrayList<Object> {

@Override
public boolean add(Object arg0) {
    if (this.contains(arg0)) {
        return false;
    }
    return super.add(arg0);
}

}









Related Tutorials/Questions & Answers:
Java ArrayList
Java ArrayList   How to declare unique ArrayList
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
Advertisements
Java arraylist of arraylist
Java arrayList can make the use of other arrayList.  In one arrayList other arrayList can be added as the object  It works as two dimension array. Example of Java Arraylist of Arraylist import
java arraylist
help how to handle this through java arraylist. xml : <?xml version='1.0...java arraylist  Hi, Thanks in advance.. From the xml given below i need to create arraylist whose name is same as type value(e.g : list1,list2
Java arraylist, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
ArrayList in java
ArrayList in java  sir i have a class Student.it contains id,name,marks of students and a parameteraised constructor.now i created an arraylist... to access marks from arraylist
Java ArrayList Example
Java ArrayList Example  How can we use array list in java program..."); array.add("Arun"); System.out.println("ArrayList Size...++){ System.out.println("ArrayList Element"+i+" :"+array.get(i
Core Java-ArrayList
Core Java-ArrayList  How do i find duplicates in ArrayList. First i add some elements to ArrayList, then how do i find the duplicates and show the duplicate elements. Give an example
arraylist
arraylist   Using arraylist class , what type of exception are throws, how can write a java programe   An ArrayList can throw... ArraylistException { void buildAlphabet() { ArrayList list = new ArrayList
ARRAYLIST CODE - Java Beginners
ARRAYLIST CODE  HELLO SIR,I AM VERY NEW TO JAVA FIELD,HOW TO READ ELEMENTS FROM TWO ARRAYLIST AND PRINT THE ELEMENTS WHICH ARE COMMON TO TWO ARRAYLIST IN ONE LINE AND OTHER IN NEXT LINE,PLZ HELP ME.IN ADVANCE THANK U VERY
maximum size of arraylist - java
maximum size of arraylist - java  1.what is the maximum size of arraylist? 2.what is the drawback of arralist? 2.what is the drawback of JDBC? 4.how many access specifier and how many access modifier in java? 5.what
Java arraylist duplicate elements search
Java arraylist duplicate elements search  hi, please help me finding the no of duplicates elements in an arraylist example an arraylist contains elements like: mac raj mohan frank mac tom raj mohan frank result: mac 2 raj
arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many type of modifier are there in java? Thanks kalins anik   Remove
arraylist - Java Beginners
arraylist  Hi.. I've an arraylist where i need to add a string array along with other string values. My string array is array[] and arraylist is al i added other string values name,time,date as al.add(name); al.add(time
arraylist problem - Java Beginners
arraylist problem  Hello.... I wrote the following code for adding a string array into an array list along with other strings... and to display...{ ArrayList al = new ArrayList(); for(int i=0;i<10;i++){ String event
Java arraylist index() Function
Java arrayList has index for each added element. This index starts from 0. arrayList values can be retrieved by the get(index) method. Example of Java Arraylist Index() Function import
arrayList - Java Beginners
must check through the desktop arraylist and notebook arraylist. How can I combine this two arraylist checking for throw out the msg of "Computer list is empty!" Currently I only can check for desktop arraylist empty if no desktop is added
Java arraylist iterator
ArrayList has iterator() method.Using iterator() method  elements of the arraylist easily gets retrieved. iterator() can be used in the for loop. It is clear by the given example. Example of Java Arraylist
ArrayList
ArrayList  import java.util.*; class ArrayListDemo2 { public static void main(String args[]) { ArrayList al=new ArrayList(); al.add("one"); al.add("two"); al.add("three"); al.add("four"); for(int i=0;i Expected
Java new arraylist
Java ArrayList object is created with the reference of List interface Object is also created directly by the ArrayList class Java New Arraylist..."}; //ArrayList list=new ArrayList(); List list=new ArrayList(); list.add(ar[0
ArrayList - Java Beginners
"); //Vector vector=new Vector(); ArrayList arfray=new ArrayList...("Show All"); Vector vector=new Vector(); ArrayList arfray=new ArrayList
Java ArrayList sublist
It returns the part of the ArrayList as List reference. part is the given range between two indexes. Java Arraylist Sublist Example import...) { String  ar[]={"india","pakistan","United Kingdom","Japan","Korea"}; ArrayList
Java ArrayList removeall
the elements from list1 which is present in the list2 Java Arraylist Removeall...","Korea"}; ArrayList list=new ArrayList(); ArrayList list1=new ArrayList
Java ArrayList clone
It returns the copy of the given ArrayList object as the Object class. So it must be casted to the ArrayList for further use. Java Arraylist...","Japan"}; ArrayList list=new ArrayList(); list.add(ar[0]); list.add(ar[1
arraylist
arraylist  Hi How can we eliminet duplicate element from arraylist? How can we find highest salary from arraylist ? How can we highest key value pair from map? Thanks Kalins Naik   Remove duplicates from Arraylist
Java arraylist for loop
Elements of the ArrayList can be easily added and retrieved by the for loop. Example FOR Java arraylist for loop import java.util.ArrayList...(String[] args) {         List list=new ArrayList();         String names
arraylist
arraylist  Hi i have class A , i have added employee name and id in arraylist, then how can i find out all infomation of class A using emplyee... data into an arraylist and display the data of the particular employee according
ArrayList - Java Beginners
in reverse order. (i don't know which programming is it, i think it is java
arraylist
% *(noOfYearService/2). Store each employee information in different arrayList depending on his
Java arraylist merge
is joined in to the list1. Example Java Arraylist Merge import... In Java Two arrays can be joined by using the Collection list...};         List list1=new ArrayList();         List list2=new ArrayList
arraylist declaration in java
of the List interface Example of Java Arraylist Declaration import... void main(String[] args) {         List list=new ArrayList();         String
Arraylist in java
ArrayList is a class that extends AbstractList and implements List Interface. Standard java array are of fixed length, that mean we should know the size.... but for indefinite number of elements Arraylist is used as it creates dynamic Array
How to create new arraylist using Java
someone provides online example how to create new arraylist in java programming... arraylist Java. The Java ArrayList object is created with the reference of List...How to create new arraylist using Java  hi, I want to develop
Java arraylist to array
Java arrayList has method toArray() It converts the given list... be used properly. Example of Java Arraylist to Array import...) {      int ar[]={444,222,333,111};      ArrayList list=new ArrayList
arraylist size in the Java program
size() function gives  the total number of elements present in the arrayList. Example of Java Arraylist Size() Function...[]={33.4f,66.78f,77.8f};       List list=new ArrayList();          for (float f:fr
Java arraylist generics example and arraylist generic list
feature of java 5. When the ArrayList is generalized for a specific data... data type element. Example of Java Generic Arraylist import... static void main(String[] args) {       List list=new ArrayList
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
arraylist of an arraylist
arraylist of an arraylist  Can anyone suggest me how to use arraylist of an arraylist?? how to put data into it and get data from it???? becoz i want to make rows and column dynamic which can grow as per requirement?????/ plz
Java arraylist of objects
In arrayList object is added by default This can be object of String, Integer or any Wrapper class Example of Java Arraylist... ArrayList(4);        list.add(0,name2);        list.add(1,name1
arraylist vs vector - Java Beginners
arraylist vs vector  hi, i want to know what is the difference between arraylist and vector in case of performance. in what cases we should go for arraylist and in what case we should go for vector. is there any   array
Java ArrayList Addall
list. Java Arraylist Addall Example import java.util.*; public...","pakistan","United Kingdom","Japan"}; List list=new ArrayList(); list.add(ar... ArrayList(); list1.add("delhi"); list1.add("islamabad"); list1.add("britain
Java ArrayList clear
It removes all the elements of the given list and returns empty list But the remove method removes element one by one Java Arraylist Clear... list=new ArrayList(); list.add(ar[0]); list.add(ar[1]); list.add(ar[2
How to sort ArrayList in java
How to sort ArrayList in java In this section you will learn how to sort ArrayList in java. ArrayList support dynamic array that can grow as needed. Array... which sort the Arraylist. Now here is the code to sort the ArrayList in java
Collections arraylist - Java Interview Questions
main(String[] args) { ArrayList al=new ArrayList(); al.add("1"); al.add("2
Give difference between LinkedList and ArrayList - Java Beginners
is the use of LinkedList and ArrayList? How you can difference between LinkedList and ArrayList? Provide examples of each. Thanks   Hi Friend, Differences: ArrayList provides fast radom access while LinkedList does
Java arraylist sort
of Java Arraylist Sort import java.util.ArrayList; import... ArrayList doesn't have sort() method. We can use the static sort ... main(String[] args) {      Integer ar[]={444,222,333,111};      ArrayList list
How to convert Arraylist into String Array Java
How to convert Arraylist into String Array Java  Hi, I am beginners of Java programming. Can somebody Suggest me how to convert arraylist to string...://www.roseindia.net/tutorial/java/collections/arraylist/arraylisttostringarray.html
How to check if an arraylist contains a value in Java
to do this? How to check if an arraylist contains a value in Java? Thanks  ...How to check if an arraylist contains a value in Java  Hi, I have an array list object in Java with few values. I want to check if it contains
java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have an arraylist contains [a,b,value,c,d,value]when ever value comes it will split...[] args) { ArrayList al = new ArrayList(); al.add("a"); al.add("b

Ads