Is there any way to convert a CharSequence
to an array of char
s? Why doesn't the interface have a method to get characters as an array?
Asked
Active
Viewed 3,011 times
3

Mahozad
- 18,032
- 13
- 118
- 133
-
Probably because it was created before default methods existed and they didn't go back and add them. – Peter Lawrey Jul 29 '18 at 08:48
-
4(Not probably, definitely) – Stephen C Jul 29 '18 at 09:18
-
See this. https://stackoverflow.com/questions/299606/java-convert-a-char-to-a-charsequence – Chester Fung Mar 09 '23 at 15:02
1 Answers
2
I first convert the CharSequence
to String
and then get it as character array:
public char[] getAsCharArray(CharSequence input) {
return input.toString().toCharArray();
}

Mahozad
- 18,032
- 13
- 118
- 133
-
4Is it a way to do it w/o `toString()`? Assume char sequence contains a password. – ivan.ukr Apr 11 '21 at 20:12