Mr.*_*ool 4 java collections list arraylist
我有一个问题处理列表,我有三个类命名为UserInf,用户数据,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;
}
Run Code Online (Sandbox Code Playgroud)
在我的其他类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
}
Run Code Online (Sandbox Code Playgroud)
在我的其他类userprocees中,我想将userInformation列表分配给另一个列表我为userInf类创建了对象ang获取属性并分配给我的新列表
List<UserInf> userProcessList=new ArrayList<UserInf>();
UserInf userProcess=new UserInf();
userProcess.getData();
userProcess.getUserId();
userProcessList.add(userProcess);//problem is here
Run Code Online (Sandbox Code Playgroud)
但这不是如何将列表分配给java中的另一个列表
小智 6
你可以试试这个:
List<Int32> copy = new List<Int32>(original);
List<Int32> copy = original.ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18072 次 |
| 最近记录: |