• 通过将输入的5个字符串,存储在arraylist,转换成字符串输出


    实现

    点击查看代码
    package ArrayListTest;
    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class bianli {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            ArrayList<String> arrayList= new ArrayList<String>();
            for (int i = 0; i < 5; i++) {
                arrayList.add(i,scanner.next());
            }
            String string = arraytoString(arrayList);
            System.out.println(string);
        }
    
        //输出集合中的元素
        public static String arraytoString(ArrayList<String> array) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("[");
            for (int i = 0; i < array.size(); i++) {
                if (i == array.size() - 1) {
                    stringBuilder.append(array.get(i));
                } else {
                    stringBuilder.append(array.get(i)).append(",");
                }
            }
            stringBuilder.append("]");
            String string = stringBuilder.toString();
            return string;
        }
    }
    
    
  • 相关阅读:
    HDU4112
    HDU1059 二进制拆分优化多重背包
    HDU1087
    HDU1978How Many Ways 记忆化dfs+dp
    HDU1160FatMouse's Speed
    HDU1503Advanced Fruits
    CF337C
    337BRoutine Problem
    【★★★★★模板专区★★★★★】
    【水】Jam计数法
  • 原文地址:https://www.cnblogs.com/spacexlxl/p/15915538.html
Copyright © 2020-2023  润新知