【问题标题】:Edit string array elements编辑字符串数组元素
【发布时间】:2016-03-17 09:53:25
【问题描述】:

我的数组是这样的:

"keys": [
        "first name",
        "second name",
        "date of birth",
        "name",
        "tle no",
        "other details"
    ]

我想像这样重新排列上面的数组数据:

"keys": [
            "first_name",
            "second_name",
            "date_of_birth",
            "name",
            "tle_no",
            "other_details"
        ]

我想使用 java 代码创建它。如何创建它?

【问题讨论】:

  • 我假设date of_birth 应该是date_of_birth
  • 你是怎么得到这个数组的?那不是Java数组。你的java代码在哪里?你试过什么?

标签: java arrays json


【解决方案1】:

使用String.replaceAll() 方法:

for (int i = 0; i < keys.length; i++) {
    keys[i] = keys[i].replaceAll(" ", "_");
}

参考:replaceAll

【讨论】:

    【解决方案2】:

    如果您想用_ 替换(空格),那么只需使用string.replace(" ", "_")`

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多