我在处理列表时遇到了一个问题,我有三个类:UserInf、userData和userProcess,我使用UserInf类创建了一个通用列表,我需要将该列表设置为userProcess类中的另一个列表。以下是我的示例代码:
public class UserInf
{
private List<Data> pData;
private String userId;
public void setData(List<Data> pData)
{
this.pData=pData;// Need to assign the fpData
}
public List<Data> getData()
{
return this.pData;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String getUserId()
{
return userId;
}
在我的另一个userdata类中,我使用userInf创建了列表,并像这样添加值:
List<UserInf> userInformation=new ArrayList<UserInf>();
UserInf userInfo=new UserInf();
userInfo.setUserId(userid);
userInfo.setData(pdata);
userInformation.add(userInfo);//up to this working fine
}
在我的另一个 userprocees 类中,我想将 userInformation 列表分配给我创建的另一个列表对象以获取属性并分配给我的新列表。
List<UserInf> userProcessList=new ArrayList<UserInf>();
UserInf userProcess=new UserInf();
userProcess.getData();
userProcess.getUserId();
userProcessList.add(userProcess);//problem is here
但是这种方法在Java中如何将一个列表赋值给另一个列表并不起作用。
UserInf userProcess = new UserInf();
没有意义,为什么要执行userProcess.getData();
和userProcess.getUserId();
?此时pData
和userId
是否仍然为null
? - Crazenezz