【问题标题】:Using a hashtable to replace values characters within an array使用哈希表替换数组中的值字符
【发布时间】:2015-01-18 21:38:04
【问题描述】:

所以我有一个哈希表,其结构类似于"m" : "q",其中第一个字符是我们要搜索的内容,然后用第二个字符替换它。现在我有一个数组,每个元素都是一个字符串,需要在进行交换时打印。所以问题是我该怎么做?考虑到替换,数组无法更改。

【问题讨论】:

  • 你能粘贴你的代码来看看你到底在做什么吗?
  • @GeorgeSmith 你觉得可以分享一下相关代码吗?

标签: java hashtable


【解决方案1】:
public void swapCharactersAndPrint(String[] data, Map<Character, Character> replacements) {
        for (String string : data) {
            for (char c : string.toCharArray()) {
                if (replacements.containsKey(c)) System.out.print(replacements.get(c));
                else System.out.print(c);
            }
            System.out.println();
        }
    }

【讨论】:

    猜你喜欢
    • 2014-07-25
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2017-01-16
    • 2014-11-06
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多