Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Reverse-a-string/Java/reverse-a-string-3.java
Normal file
24
Task/Reverse-a-string/Java/reverse-a-string-3.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import java.text.BreakIterator;
|
||||
|
||||
public class Reverse {
|
||||
/* works with Java 20+ only
|
||||
* cf. https://bugs.openjdk.org/browse/JDK-8291660
|
||||
*/
|
||||
public static StringBuilder graphemeReverse(String text) {
|
||||
BreakIterator boundary = BreakIterator.getCharacterInstance();
|
||||
boundary.setText(text);
|
||||
StringBuilder reversed = new StringBuilder();
|
||||
int end = boundary.last();
|
||||
int start = boundary.previous();
|
||||
while (start != BreakIterator.DONE) {
|
||||
reversed.append(text.substring(start, end));
|
||||
end = start;
|
||||
start = boundary.previous();
|
||||
}
|
||||
return reversed;
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
String a = "as⃝df̅";
|
||||
System.out.println(graphemeReverse(a)); // f̅ds⃝a
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue