我有三个泛型类型的列表。我想将它们组合成一个List并从函数返回但我不知道如何将它转换为一个对象。这是我的代码.......
public class WrapUpCodes
{
public Map<Long, W_Code> codes= new HashMap<>();
public Map<Long, S_Services> services= new HashMap<>();
public Map<Long, S_Group> skills= new HashMap<>();
public WrapUpCodes(){}
public WrapUpCodes(String dnis, String skillgroup)
{
populateResultString( dnis, skillgroup);
}
public void populateResultString(String dnis, String skillgroup)
{
DBCPSource conn= new DBCPSource();
String[] Res = null;
try
{
Res = conn.GetwrapUpCodes(dnis, skillgroup);
}
catch (Exception e)
{
e.printStackTrace();
}
String code[] =Res[0].split(",");
long keyValue = 1;
for(int k=0; k<code.length; k++)
{
codes.put(keyValue, new W_Code (code[k]));
keyValue = keyValue+1;
}
String ser [] = Res[1].split(",");
keyValue=1;
for(int j=0; j<ser.length; j++)
{
services.put(keyValue, new S_Services(ser[j]));
keyValue= keyValue+1;
}
String SG [] = Res[2].split(",");
keyValue=1;
for(int j=0; j<SG.length; j++)
{
skills.put(keyValue, new S_Group(SG[j]));
keyValue= keyValue+1;
}
}
public List<List<String>> getAllCodes()
{
ArrayList<S_Group> SG= new ArrayList<S_Group>(skills.values());
ArrayList<W_Code> WC= new ArrayList<W_Code> (codes.values());
ArrayList<S_Services> SER= new ArrayList<S_Services> (services.values());
}
}
I am getting problem in this function.
public List<List<String>> getAllCodes()
{
ArrayList<S_Group> SG= new ArrayList<S_Group>(skills.values());
ArrayList<W_Code> WC= new ArrayList<W_Code> (codes.values());
ArrayList<S_Services> SER= new ArrayList<S_Services> (services.values());
}
}
我想要归还所有三个ArraLists。任何人都可以帮我解决这个问题。
答案 0 :(得分:2)
返回一个数据对象:
public static class CodeData {
public final ArrayList<S_Group> groups = new ArrayList<>();
public final ArrayList<W_Code> codes = new ArrayList<>();
public final ArrayList<S_Services> services = new ArrayList<>();
}
public CodeData getAllCodes()
{
CodeData data = new CodeData();
data.groups.addAll(skills.values());
data.codes.addAll(codes.values());
data.services.addAll(services.values());
return data;
}