Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
Never
import java.util.LinkedHashSet;
import java.util.Set;

import public class user;

public class UserSet {

	public static void main(String[] args) {
		// create multiple employee object
		User user1 = new User(1001, "John Smith", "J.Smith@cat.com", "Mother", "Male");
		User user2 = new User(1002, "Marry William","M.Williams@cat.com", "Father", "Female");
		User user3 = new User(1003, "Ava Smith", "A.Smith@cat.com", "1234", "Feale");
		User user4 = new User(1004, "David Bakum", "D.Bakum@ms.com", "$56#", "Male");
		User user5 = new User(1005, "Amar Singh", "A.Singh@punjab.com", "Lahore", "Male");

		// create a set of users
		Set<User> setOfUsers = new LinkedHashSet<User>();

		// add elements in set
		setOfUsers.add(user1);
		setOfUsers.add(user2);
		setOfUsers.add(user3);
		setOfUsers.add(user4);
		setOfUsers.add(user5);		

		System.out.println(setOfUsers);

		// enhanced for loop
		for (User usr : setOfUsers) {
			System.out.println("-------------------------");
			System.out.println(usr.id);
			System.out.println(usr.name);
			System.out.println(usr.password);
			System.out.println(usr.gender);
			
		}
	}