boolean contains(Object o) Example Program


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 such that (o==null ? e==null : o.equals(e)).

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.contains(Object o) method returns true
 *              if this list contains the specified element.
 */
public class LinkedListContains {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("kamal");
		System.out.println("LinkedList:" + list);
		System.out.println("List contains 'kamal':" + list.contains("kamal"));
		System.out.println("List contains 'mohan':" + list.contains("mohan"));
	}
}

Output

LinkedList:[anandh, hari, vinoth, kamal]
List contains 'kamal':true
List contains 'mohan':false

Explanation

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 such that (o==null ? e==null : o.equals(e)).

Specified by:
contains in interface Collection<E>

Specified by:
contains in interface Deque<E>

Specified by:
contains in interface List<E>

Overrides:
contains in class AbstractCollection<E>

Parameters:
o - element whose presence in this list is to be tested

Returns:
true if this list contains the specified element


Related Post

Comments


©candidjava.com