Questions tagged [charsequence]

In Java (and related languages such as Scala), java.lang.CharSequence is an interface to sequences of character values.

For more information, see the Java 8 specification of CharSequence.

146 questions
3
votes
1 answer

CharSequence interface in Java 11 added method `compare`. Why not `compareTo` of Comparable interface?

The CharSequence interface gained a new static method in Java 11: compare. This method returns an int: the value 0 if the two CharSequence are equal; a negative integer if the first CharSequence is lexicographically less than the second; or a…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
3
votes
1 answer

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?
Mahozad
  • 18,032
  • 13
  • 118
  • 133
3
votes
1 answer

Pass a CharSequence to a Scanner in Java

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…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
3
votes
3 answers

When to use String.subSequence method over String.subString?

I know subSequence returns a charSequence which is a read-only. Also, String class implements CharSequence. subString returns a String. But, amongst subsequence and substring, when and which one to prefer
user3758749
  • 117
  • 1
  • 2
  • 6
3
votes
3 answers

Instantiating a interface CharSequence

CharSequence[] items = { “Google”, “Apple”, “Microsoft” }; if CharSequence is an interface then, in the above example aren't we instantiating a interface?
3
votes
2 answers

How to get an EXACT Character in a CharSequence?

I want to extract only the exact character in a CharSequence when I know the position (or key) of the character in it! For eg: In the CharSequence "HELLO" I want to Extract the letter in the position 2 which is "E" in this case . How can I do…
Adit Gupta
  • 863
  • 3
  • 8
  • 23
3
votes
1 answer

Remove underline from a string in Java/Android

I'm getting text input from an editText and setting it as a notification .setTitle, but when it shows in the notification, it shows up with an underline on certain words. I had no idea why, but when I went to test it, the android keyboard puts…
EGHDK
  • 17,818
  • 45
  • 129
  • 204
2
votes
1 answer

Converting ArrayList to CharSequence[]

I want to convert my ArrayList containing elements with the toString method shadowed in "T": public String toString(){ return name + " " + realname; } to a CharSequence array containing all the "T"s toString. Checked some stuff out but nothing…
Mazze
  • 1,354
  • 4
  • 17
  • 35
2
votes
3 answers

Parse a date from a CharSequence with standard patterns…

I'm writing a parser for a command line interface of an external tool and I'm using Scala's parser combinators library. As part of this I need to parse a standard date of the format EEE MMM d HH:mm:ss yyyy Z. Scala's parser-combinators are…
Viktor Hedefalk
  • 3,572
  • 3
  • 33
  • 48
2
votes
1 answer

Casting String to Charsequence

What is the purpose of casting String to CharSequence explicitly? String itself implements CharSequence interface. Spring 4.x supports Java 6+ and CharSequence is present since 1.4. Code snippet from Spring Framework: public static boolean…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
2
votes
1 answer

Scala SBT fails - error while loading CharSequence (Scala 2.12.1, SBT 0.13.13)

i've seen that people are getting same error messages (error: error while loading CharSequence, class file '...\rt.jar(java/lang/CharSequence.class)' is broken (bad constant pool tag 15 at byte 1470) and the most commont fix was to downgrade or…
Laimonas Sutkus
  • 3,247
  • 2
  • 26
  • 47
2
votes
0 answers

Why does Java CharSequence.chars() return an IntStream?

This behaviour seems strange to me. As you can probably guess I'd expect it to return something that would allow me to process the Characters of the String without having to cast.
Simon Morgan
  • 2,018
  • 5
  • 23
  • 36
2
votes
1 answer

operator + cannot be applied to java.lang.charsequence

Trying to make a calculator, here's the button method when the line with the * is ran it comes up with the error "operator + cannot be applied to java.lang.charsequence". If any one know's a way around this please help. public void…
Kyle Wilko
  • 23
  • 3
2
votes
2 answers

What is the return type of TextView.getText() in android?

Why does TextView.getText() return a CharSequence instead of a String? (String is the implementation of the CharSequence)
ChrisMcJava
  • 2,145
  • 5
  • 25
  • 33
2
votes
2 answers

Why do so many of the Java libraries take `String` where `CharSequence` would do?

I was frustrated recently in this question where OP wanted to change the format of the output depending on a feature of the number being formatted. The natural mechanism would be to construct the format dynamically but because PrintStream.format…
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
1 2
3
9 10