11:19 pm - Sunday July 15, 2018

Vector Example Program for retainAll(Collection c)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@author: candidjava
@description: retainAll(Collection c)is used to Retains only the elements in this Vector that are contained in the specified Collection.
 */
import java.util.*;

public class DeeRetainAllVector {
	public static void main(String[] args) {
		LinkedList l = new LinkedList();// create the linked list
		l.add("a");// add the elements
		l.add("n");// add the elements
		Vector v = new Vector();// create the vector
		v.add('d'); // add the elements
		v.add('e'); // add the elements
		v.add('e'); // add the elements
		v.add('p'); // add the elements
		v.add('a'); // add the elements
		v.add('n'); // add the elements
		System.out.println("the elements are: " + v);// to print the vector
							// elements
		boolean b = v.retainAll(l);// Retains only the elements
			// in this Vector that are contained in the specified
			// Collection. If the retain elements is
			// present mean return true otherwise false
		System.out.println(b);
	}
}


output
the elements are: [d, e, e, p, a, n]
true

Filed in: Z-A All Java Codes

Comments are closed.