【问题标题】:How to change/replace index values dyanmically in list using java如何使用java在列表中动态更改/替换索引值
【发布时间】:2022-01-10 01:31:13
【问题描述】:

我想更改列表中的值

实际输出: “概括”: [ { 值a:“1”, 标题计数:“20” } ]

必填项: “概括”: [ { 值 A:“1”, 标题计数:“20” } ]

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

【问题讨论】:

  • 分割文本和大写字母的标准是什么?此外,这似乎是列表中的地图。你能添加一些产生这个的Java代码吗?这将有助于帮助者。 :)

标签: java list arraylist


【解决方案1】:

可能是这样的(假设 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));
}

当运行到控制台窗口的输出将是:

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

【讨论】:

    猜你喜欢
    • 2014-02-20
    • 2012-03-23
    • 2019-06-14
    • 2019-09-18
    • 2017-09-05
    • 2022-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多