Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

List with out duplicates

Ads

 
 

Share on Google+Share on Google+

abheeshekreddy
List with out duplicates
1 Answer(s)      8 years ago
Posted in : Java Interview Questions
Ads
View Answers

December 1, 2008 at 1:32 AM


Hi friend,

Use contains(Object o) method of Interface List

public boolean contains(Object o)

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e.


import java.util.*;

class ListExample
{
public static void main(String[] args)
{
List arList = new ArrayList();
arList.add("a");
arList.add("b");
arList.add("c");
arList.add("d");
if(arList.contains("b"))
{
System.out.println("Element is already exists.");
}

}
}



Thanks

Ads









Related Tutorials/Questions & Answers:
List with out duplicates - Java Interview Questions
List with out duplicates   Hi all, Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates..., Use contains(Object o) method of Interface List public boolean contains(Object
List out different arguments in PHP header function?
List out different arguments in PHP header function?   List out different arguments in PHP header function
Advertisements
Duplicates - Hibernate
please help me out. Im using composite as primary key. Please help me out
Finding duplicates using array in for loop
Finding duplicates using array in for loop  how to find the duplicates in array using for loop
how to get data from list to map with out using a loop?
how to get data from list to map with out using a loop?  List list=new ArrayList(); list.add("raja"); list.add("1"); list.add("puja...("15"); how to get this data into map with out using a loop. i want
Eliminate Duplicates in Arraylist - Java Interview Questions
Eliminate Duplicates in Arraylist    Hi Friends, Can any one give sample code for removing duplicates in arraylist and hashmap. Thank u in advance.  Hi friend, Code to help in solving the problem
program to display all words in the file in the sorted order without duplicates
program to display all words in the file in the sorted order without duplicates  I want a java program which accepts a file from user and displays all words in the file in the sorted order without duplicates
Creating custom output using XMLUnit - MatchTracker duplicates the output data
Creating custom output using XMLUnit - MatchTracker duplicates the output data  how to create a custom output using xmlunit, I have tried it and used MatchTracker, but the match tracker was repeated for the total number of nodes
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
Is there anyone out there?
Is there anyone out there?  Hi please could somebody respond as I am seeking advice but not getting any and do not know whether or not to continue using this site
Version of com.little-fluffy-clouds>testng-system-out-printer dependency
List of Version of com.little-fluffy-clouds>testng-system-out-printer dependency
Version of com.little-fluffy-clouds>testng-system-out-printer dependency
List of Version of com.little-fluffy-clouds>testng-system-out-printer dependency
JSP Out Object
JSP Out Object  JSP Out Object?   out object denotes... of the object out is jsp.JspWriter. The out object "Javax.servlet.jsp.JspWriter". Methods of out Object: clear() clearBuffer() flush() isAutoFlush() getBufferSize
with out class - Java Beginners
with out class  can we write a program with out a class in core java?if yes,give example
drawing out of bounds
drawing out of bounds  How to throw an exception when a rectangle goes out of the boundaries of a JFrame. The program is asking to draw a triangle, and resize it. If the triagle size goes out of the JFrame throw an execption. I
How to list all drives available in the system
How to list all drives available in the system In this section, you will learn how to list out all the drives available in the system.  Description of code: To get the list of drives, we have called the method listRoots() of File
UIWebView Zoom in and out
UIWebView Zoom in and out  Hi, Can anyone give me the example of tap and zoom in and out the pdf loaded on uiwebview?? Thanks
In and Out parameters - SQL
In and Out parameters  What are in and out parameters in stored... parameters-IN,OUT,INOUT. 1)IN: It is default parameter which is passed...)OUT: This parameter does not supply any value to the procedure.It is assumed
help me out...!!!!
help me out...!!!!  i have to make a project on console based application in java.. so can anyone guide me with some gd ideas that can be implemented
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
SQL Out Parameter
SQL Out Parameter       SQL Out Parameter allows the stored procedure to the pass data value ... from SQL Out Parameter .In this Example we create a procedure 'abc
JSp session time out
JSp session time out  Consider a case where we are working on a java application.After few hours of continuous work ,my application gets logged out... it gets logged out in the middle i.e during our work....why is it so
List
List  getting values from a form and make a list of them and store them into database
Out Of Memory Exception Erorr
Out Of Memory Exception Erorr  hello how are you?I hope you are fine I'm using jgrasp program my problem is in java programming my program compiled with no problem but when I run it this exception appears: Exception
Please help me out
Please help me out    Description* You are hired to develop a laptop inventory information system for Sheridan College in order to keep track of the information about the laptops lent to the students. Users can add or remove data
Find out last character of array
Find out last character of array  How we can find out the last character of array in java program
Getting list of Local Interfaces on a machine
to find out the total no of list of local interfaces available on a machine. Here... Getting list of Local Interfaces on a machine... the list of local interfaces with the machine name and machine IP Address. Here
Fading elements in and out example
Fading elements in and out example       Fading elements in and out example..., a list is given , if we hover on first two element, "<<<"
Java Swing code for zoom in and out
Java Swing code for zoom in and out  hi.......... I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help
list - Java Interview Questions
list  Hi all Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates then what should be the logic...) method of Interface List public boolean contains(Object o) Returns
JavaScript Zoom in and Zoom out
illustrates you how to zoom in and zoom out of an image using JavaScript. Here we... and width of the image and make it to show the effect Zoom In and Zoom Out... the image zoom in and zoom out. As long as you put the cursor on the link Zoom