12:52 am - Thursday July 27, 2017

Stack 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.com
@description:Stack example program for retainAll(Collection C)

 */

import java.util.Stack;

public class StackRetainAll {
	public static void main(String[] args) {

		Stack s1 = new Stack(); // creating first stack

		for (int i = 1; i <= 10; i++) {

			s1.push(i);

		}

		Stack s2 = new Stack(); // creating second stack

		for (int i = 1; i <= 5; i++) {

			s2.push(i);

		}

		System.out.println(s1.retainAll(s2));
		System.out.println(s1); // print values which are common in stack

	}
}

//OUTPUT:
true
[1, 2, 3, 4, 5]

Filed in: Z-A All Java Codes

Comments are closed.