1
データを一致させて新しい値に置き換えますが、5908行以上のデータをHashMapに配置したいとします。それはエラーが出ます。この問題または別の解決方法を解決するには?HashMapの問題を使用して5908以上のデータ行にマッピングする
String str = "aaa bob ccc ddd .....";
HashMap<String, String> map = new HashMap<>();
map.put("aaa","eee"); // data that I would like to match and replace it
map.put("ddd","fff");
.
.
. // more than 5908 lines
.
.
map.put("zzz"."yyy");
Pattern pattern = Pattern.compile("([a-zA-Z_]+)");
Matcher matcher = pattern.matcher(str) // matching process
StringBuffer sb = new StringBuffer();
while(matcher.find()) { // if found and replace
String replace = map.get(matcher.group());
if (replace == null) { // if not just print it back
replace = matcher.group();
}
matcher.appendReplacement(sb, replace + "");
}
matcher.appendTail(sb);
System.out.println(sb);