Eingabe: < /p>
Ein Akronym ist eine Art Abkürzung, die gebildet wird, indem die Ausgangsbuchstaben einer Phrase genommen und ein neues Wort erstellt werden. Akronyme werden oft als Wörter ausgesprochen.
public class AbbreviationFinderTool {
public static void main(String[] args) {
String filePath = "C:\\MYCODE\\SCPOProjectTool\\INPUT\\aaa.txt"; // Path to your input file
// List of allowed "connector" words in abbreviations
List allowedWords = Arrays.asList("of", "for", "and", "or", "with");
// Regex to match abbreviations allowing connectors and multiple capitalized words
String regex = "([A-Z][a-z]+\\s)*(of|for|and|or|with\\s)*([A-Z][a-z]+\\s?)+";
Pattern pattern = Pattern.compile(regex);
try (Stream lines = Files.lines(Paths.get(filePath))) {
lines.forEach(line -> {
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
String abbreviation = matcher.group().trim();
if (isValidAbbreviation(abbreviation, allowedWords)) {
System.out.println(abbreviation);
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
// Validates if the extracted phrase is a proper abbreviation
private static boolean isValidAbbreviation(String phrase, List allowedWords) {
String[] words = phrase.split("\\s+");
return Arrays.stream(words).allMatch(word ->
Character.isUpperCase(word.charAt(0)) || allowedWords.contains(word.toLowerCase())
);
}
}
< /code>
Tatsächliche Ausgabe: < /p>
Write
Title
Find
Acronys
Input
An
Acronyms
National Aeronautics
Space Administration
Random Access Memory
Abbreviations
Acronyms
United Nations International Children
Emergency Fund
< /code>
Erwartete Ausgabe: < /p>
National Aeronautics and Space Administration
Random Access Memory
United Nations International Children's Emergency Fund
Eingabe: < /p> Ein Akronym ist eine Art Abkürzung, die gebildet wird, indem die Ausgangsbuchstaben einer Phrase genommen und ein neues Wort erstellt werden. Akronyme werden oft als Wörter ausgesprochen.[code]public class AbbreviationFinderTool { public static void main(String[] args) { String filePath = "C:\\MYCODE\\SCPOProjectTool\\INPUT\\aaa.txt"; // Path to your input file
// List of allowed "connector" words in abbreviations List allowedWords = Arrays.asList("of", "for", "and", "or", "with");
// Regex to match abbreviations allowing connectors and multiple capitalized words String regex = "([A-Z][a-z]+\\s)*(of|for|and|or|with\\s)*([A-Z][a-z]+\\s?)+"; Pattern pattern = Pattern.compile(regex);
// Validates if the extracted phrase is a proper abbreviation private static boolean isValidAbbreviation(String phrase, List allowedWords) { String[] words = phrase.split("\\s+"); return Arrays.stream(words).allMatch(word -> Character.isUpperCase(word.charAt(0)) || allowedWords.contains(word.toLowerCase()) ); } } < /code> Tatsächliche Ausgabe: < /p> Write Title Find Acronys Input An Acronyms National Aeronautics Space Administration Random Access Memory Abbreviations Acronyms United Nations International Children Emergency Fund < /code> Erwartete Ausgabe: < /p> National Aeronautics and Space Administration Random Access Memory United Nations International Children's Emergency Fund [/code] Bitte helfen Sie mir.
Eingabe:
Ein Akronym ist eine Art Abkürzung, die gebildet wird, indem die Ausgangsbuchstaben einer Phrase genommen und ein neues Wort erstellt werden. Akronyme werden oft als Wörter ausgesprochen....
Ich habe den folgenden Codeausschnitt, in dem ich versuche, Null-IDs aus Beans zu entfernen und mithilfe eines Komparators zu sortieren. Ich wollte die Implementierung mithilfe von Java-Streams...
Ist es möglich, Werte mit Streams zusammenzufassen? Ich habe zum Beispiel eine Klasse Dataset, die eine CSV-Datei für mich in Zeilen unterteilt, die Werte enthalten:
{customer=Max , articlenr=1234,...