Java
- 2 ответа
- 0 вопросов
1
Вклад в тег
import java.util.*;
import java.util.regex.*;
public class Analyzer{
private final static Pattern LINES_NUM_PATTERN = Pattern.compile("\\d+\\s*");
public static void main(String[] args) throws InterruptedException, IOException {
Map<Integer, String> lines = new HashMap<>();
String line ="43 Hello universe!";
Matcher matcher = LINES_NUM_PATTERN.matcher(line);
if (matcher.find() && matcher.start() == 0) {
String number = matcher.group().trim();
lines.put(Integer.parseInt(number), line.substring(matcher.end()));
}
System.out.println(lines);
}
}