gpt4 book ai didi

java - 将三个通用数组列表合并为一个

转载 作者:行者123 更新时间:2023-12-02 03:44:34 25 4
gpt4 key购买 nike

我有三个泛型类型的列表。我想将它们组合成一个列表并从函数返回,但我不知道如何将其转换为一个对象。这是我的代码......

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());
}
}

我想返回所有三个 ArraList。谁能帮我解决这个问题。

最佳答案

返回数据对象:

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;
}

关于java - 将三个通用数组列表合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36423945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com