Generation

generate functionFri, 04 Nov 2022

配列に格納された特定の文字列の間の行をリストに格納する

// String[] lines; // String start = "something"; // String end = "something"; public List<String> getLinesBetween(String[] lines, String start, String end) { List<String> result = new ArrayList<String>(); boolean capture = false; for (String line : lines) { if (line.contains(start)) { capture = true; } if (capture) { result.add(line); } if (line.contains(end)) { break; } } return result; }

Questions about programming?Chat with your personal AI assistant