5:08 pm - Monday April 24, 2017

This Program is used to ‘true’ if the two specified collections have no elements in common

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

BACK

This Program is used to ‘true’ if the two specified collections have no elements in common using disjoint(Collection<?>, Collection<?>)

Example Program


import java.util.*;

public class CollectionsDemo {
	public static void main(String args[]) {
		// create two lists
		List<String> srclst = new ArrayList<String>(5);
		List<String> destlst = new ArrayList<String>(10);

		// populate two lists
		srclst.add("Java");
		srclst.add("is");
		srclst.add("best");

		destlst.add("C++");
		destlst.add("is not");
		destlst.add("older");

		// check elements in both collections
		boolean iscommon = Collections.disjoint(srclst, destlst);

		System.out.println("No commom elements: " + iscommon);
	}
}

 

Output:

No commom elements: true

Description:

The disjoint(Collection<?>, Collection<?>) method is used to ‘true’ if the two specified collections have no elements in common.

 

Declaration:

public static boolean disjoint(Collection<?> c1,Collection<?> c2)

Parameters:

  • c1–This is a collection.

  • c2–This is another collection.

Return Value:

NA

Exception:

NA

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.