The Scanner
class has a constructor taking a String
.
Scanner s = new Scanner( myString ) ;
How to feed a CharSequence
object to a new Scanner
? I could first generate a String
from the CharSequence
, but that is inefficient and rather silly.
Scanner s = new Scanner( myCharSequence.toString() ) ; // Workaround, but seems needlessly inefficient to instantiate a `String`.
I looking for a way to access the CharSequence
directly from the Scanner
. Something like this:
Scanner s = new Scanner( myCharSequence ) ; // Use `CharSequence` directly.
The Scanner
class also takes a Readable
in a constructor. Can a CharSequence
be presented as a Readable
? Or is there some other workaround?