How to storing Java Object In Vector

import java.util.Vector;

public class VectorOfObject {

public static void main(String[] args) {

Vector<User> vector = new Vector<User>();
vector.add(new User(“shivam”,100));
vector.add(new User(“raja”,200));
vector.add(new User(“mukesh”,300));
vector.add(new User(“piyush”,500));

// print vector
for (User user : vector) {
System.out.println(“user name=”+user.getName()+” User id=”+user.getUserId());



class User{

private String name;
private int userId;

public User(String name, int userId) {
super(); = name;
this.userId = userId;
public String getName() {
return name;
public void setName(String name) { = name;
public int getUserId() {
return userId;
public void setUserId(int userId) {
this.userId = userId;



user name=shivam User id=100

user name=raja User id=200

user name=mukesh User id=300

user name=piyush User id=500

Notice: compact(): Undefined variable: limits in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 9 =