Mahozad
Mahozad

Reputation: 24472

How to get character array from a CharSequence?

Is there any way to convert a CharSequence to an array of chars? Why doesn't the interface have a method to get characters as an array?

Upvotes: 3

Views: 3393

Answers (1)

Mahozad
Mahozad

Reputation: 24472

I first convert the CharSequence to String and then get it as character array:

public char[] getAsCharArray(CharSequence input) {
    return input.toString().toCharArray();
}

Upvotes: 2

Related Questions