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
462
votes
9 answers

CharSequence VS String in Java?

Programming in Android, most of the text values are expected in CharSequence. Why is that? What is the benefit, and what are the main impacts of using CharSequence over String? What are the main differences, and what issues are expected, while using…
Bite code
  • 578,959
  • 113
  • 301
  • 329
323
votes
6 answers

How to convert a String to CharSequence?

How to convert String to CharSequence in Java?
BurningIce
246
votes
6 answers

How to convert CharSequence to String?

How can I convert a Java CharSequence to a String?
Belgi
  • 14,542
  • 22
  • 58
  • 68
110
votes
8 answers

Exact difference between CharSequence and String in java

I read this previous post. Can any one say what the exact difference between CharSequence and String is, other than the fact that String implements CharSequence and that String is a sequence of character? For example: CharSequence obj =…
Amith
  • 1,907
  • 5
  • 29
  • 48
79
votes
3 answers

ArrayList to CharSequence[]

What would be the easiest way to make a CharSequence[] out of ArrayList? Sure I could iterate through every ArrayList item and copy to CharSequence array, but maybe there is better/faster way?
Laimoncijus
  • 8,615
  • 10
  • 58
  • 81
75
votes
5 answers

How to merge some spannable objects?

I divide a spannable object into 3 parts, do different operations, and then I need to merge them. Spannable str = editText.getText(); Spannable selectionSpannable = new SpannableStringBuilder(str, selectionStart, selectionEnd); Spannable…
Eugene
  • 991
  • 1
  • 6
  • 8
36
votes
7 answers

CharSequence to int

Is there a Way to converte a Charsequence or a String to an Ingeter? CharSequence cs = "123"; int number = (int) cs; I'm a Noob. Solution: CharSequence cs = "123"; int number = Integer.parseInt(cs);
passsy
  • 5,162
  • 4
  • 39
  • 65
31
votes
3 answers

Generic OR instead of AND

Is it possible to generically parameterize a method accepting EITHER ClassA OR InterfaceB ? Does Not Compile Due to | Pseudocode public void orDoer(T someData){ // ... } i.e. instead of writing multiple method…
Cel
  • 6,467
  • 8
  • 75
  • 110
30
votes
6 answers

Why String.replaceAll() in java requires 4 slashes "\\\\" in regex to actually replace "\"?

I recently noticed that, String.replaceAll(regex,replacement) behaves very weirdly when it comes to the escape-character "\"(slash) For example consider there is a string with filepath - String text = "E:\\dummypath" and we want to replace the "\\"…
Bharath
  • 543
  • 1
  • 6
  • 11
28
votes
7 answers

Most efficient way to convert a single char to a CharSequence

What's the most efficient way to pass a single char to a method expecting a CharSequence? This is what I've got: textView.setText(new String(new char[] {c} )); According to the answers given here, this is a sensible way of doing it where the input…
Graham Borland
  • 60,055
  • 21
  • 138
  • 179
26
votes
5 answers

When to use CharSequence in an API

I'm designing a public interface (API) for a package. I wonder, should I use CharSequence generally instead of String. (I'm mainly talking about the public interfaces). Are there any drawbacks of doing so? Is it considered a good practice? What…
vbence
  • 20,084
  • 9
  • 69
  • 118
23
votes
6 answers

Android, how to populate a CharSequence array dynamically (not initializing?)

How do I change something like this: CharSequence cs[] = { "foo", "bar" }; to: CharSequence cs[]; cs.add("foo"); // this is wrong... cs.add("bar"); // this is wrong...
MarcoS
  • 17,323
  • 24
  • 96
  • 174
22
votes
4 answers

R.string.value Help android notification

whats the deal with CharSequence contentTitle = R.string.value; Error cannot convert from int to CharSequence. Is there a way around this or am i missing something? i tried String s = R.string.value + ""; CharSequence contentTitle = s; it returns…
Simon
  • 451
  • 2
  • 9
  • 19
20
votes
1 answer

Choosing between CharSequence and String for an API

A String is-a CharSequence. Many methods in the Java library accept CharSequence so they operate more generally. Some classe have a String method (for example, Writer.write(String)) and also implement Appendable with an equivalent CharSequence…
Raedwald
  • 46,613
  • 43
  • 151
  • 237
19
votes
3 answers

string to charsequence

Can somebody please show me a bit of code to convert a string to charsequence?
user611089
1
2 3
9 10