欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java遍历数组并重新拼接数组里的元素

程序员文章站 2022-07-15 08:22:18
...
public ArrayList getinferfacelist(ArrayList<TaskNameList> taskNameLists) {
        String interfaceName="";
        String splitedWorkTable = "";
        ArrayList interfaceNameList =new ArrayList();
        //遍历获取作业名list里的每个作业名
        for(TaskNameList taskNameList:taskNameLists){
            splitedWorkTable = taskNameList.getTaskName();
            System.out.println("作业名:"+splitedWorkTable);
            //接口名就是作业名去掉前缀SPT_GESSPSBC-STOR_INFO
            String[] split = splitedWorkTable.split("_");
            // 遍历int数组,得到拆分作业名的每一个元素
            for (int x = 1; x < split.length; x++){
                // 先判断该元素是否为最后一个
                if (x == split.length - 1){
                    // 就直接拼接元素
                    interfaceName += split[x];
                } else{
                    // 就拼接元素和_
                    interfaceName += split[x];
                    //split[1] = split[1].replace("-", "_");
                    interfaceName += "_";
                }
            }
            interfaceNameList.add(interfaceName);
        }
        System.out.println(interfaceName);
        return interfaceNameList;
    }