私は助けが必要です、私は次のような文字列を持っています
LOCALHOST = https://192.168.56.1
「LOCALHOST」とIPアドレスを取得してHashMapに保存したい
これはこれまでの私のコードです。正規表現の使用方法がわかりませんでした。助けてください 必要な出力は HashMap {LOCALHOST=192.168.56.1} にあります
public static void main(String[] args) {
try {
String line = "LOCALHOST = https://192.168.56.1";
//this should be a hash map
ArrayList<String> urls = new ArrayList<String>();
//didnt know how to get two string
Matcher m = Pattern.compile("([^ =]+)").matcher(line);
while (m.find()) {
urls.add(m.group());
}
System.out.println(urls);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
お手伝いありがとう