繁体   English   中英

如何使用 java 在列表中动态更改/替换索引值

[英]How to change/replace index values dyanmically in list using java

我想更改列表中的值

实际上 output: "summary": [ { valuesa:"1", titlecount:"20" } ]

必填项:"summary": [ { Values A:"1", Title Count:"20" } ]

需要通过在所需区域添加大写字母和空格来更改文本。

它可能是这样的(假设 List 是字符串数组):

// Create List...
List<String[]> list = new ArrayList<>();
list.add(new String[] {"valuesa:\"1\"", "titlecount:\"10\""});
list.add(new String[] {"valuesb:\"2\"", "titlecount:\"20\""});
list.add(new String[] {"valuesc:\"3\"", "titlecount:\"30\""});
    
// Convert List...
for (String[] str : list) {
    str[0] = str[0].toUpperCase().replace("VALUES", "Values ");
    str[1] = str[1].replace("titlecount", "Title Count");
}
    
// Display List...
for (String[] str : list) {
    System.out.println(Arrays.toString(str));
}

将 output 运行到控制台时,Window 将是:

[Values A:"1", Title Count:"10"]
[Values B:"2", Title Count:"20"]
[Values C:"3", Title Count:"30"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM