我有一个处理列表的问题,我有三个名为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 cretaed列表中,添加加入这样
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列表到另一个列表我为userInf类创建对象ang获取属性并分配给我的新列表
List<UserInf> userProcessList=new ArrayList<UserInf>();
UserInf userProcess=new UserInf();
userProcess.getData();
userProcess.getUserId();
userProcessList.add(userProcess);//problem is here
,但是这是不工作如何列出这样在java中分配给另一个列表
你正在得到什么错误? –
您正试图从userProcess获取数据()。这应该设置我想。如果你在这里写错误信息,我们可以正确回答。 –
没有意义,'UserInf userProcess = new UserInf();'在创建对象之后,为什么要执行'userProcess.getData();'和'userProcess.getUserId();'?它是'pData'还是'userId'仍然是'null'? – Crazenezz