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
16
votes
5 answers

using a string resource in a Toast

My code is: public static void ToastMemoryShort (Context context) { CharSequence text = getString(R.string.toast_memoryshort); //error here Toast.makeText(context, text, Toast.LENGTH_LONG).show(); return; } but I'm getting "Cannot…
Barry
  • 1,258
  • 3
  • 13
  • 27
13
votes
3 answers

Make a string from an IntStream of code point numbers?

If I am working with Java streams, and end up with an IntStream of code point numbers for Unicode characters, how can I render a CharSequence such as a String? String output = "input_goes_here".codePoints(). ??? ; I have found a codePoints()…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
10
votes
2 answers

How to encode a CharSequence using a CharSet (without converting to String)

I want to write a CharSequence to OutputStream using a specified CharSet. Basically what a Writer initialized with the same CharSet would do, when write(String) is called. The catch is, there are many CharSequences to be written and some are pretty…
Durandal
  • 19,919
  • 4
  • 36
  • 70
9
votes
3 answers

Why isn't method String.indexOf part of interface CharSequence?

I can't see any drawbacks in making String.indexOf part of the interface CharSequence. The benefit would be that other classes like StringBuffer or StringBuilder would need to implement the indexOf methods too. So is there any design reason why…
halex
  • 16,253
  • 5
  • 58
  • 67
7
votes
6 answers

How to compare a CharSequence to a String - Android

I have a class that places a text into an arrayList. Then it makes all the variables into CharSequences, when I try to compare the variables to a String such as == "test"; it doesn't work here is my code that I use to get the variables class Item { …
user2544045
7
votes
3 answers

Convert Byte Array to Charsequence in Android

I have used the below code to convert Charsequence to Byte Array. Then I save the Byte Array as Blob to my Sqlite Database. For this , I have used the below code, public static byte[] toByteArray(CharSequence charSequence) { if…
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
6
votes
3 answers

Convert float to CharSequence in android?

I am making a throughput calculator where the user inputs data and the duration it took to download or upload and my intention is to display the throughput in varying units. However, I cannot find a way to convert float to CharSequence so I can…
Parth
  • 1,226
  • 7
  • 28
  • 49
6
votes
2 answers

Problem with strings.xml... can't pass R.string.foo as a CharSequence

I'm running a TabActivity. In the following line: spec = tabHost.newTabSpec("alltime").setIndicator(R.string.plots_allTime) .setContent(intent); I get an error because setIndicator() expects a CharSequence. I'm not really sure how to fix…
dfetter88
  • 5,381
  • 13
  • 44
  • 55
6
votes
3 answers

How to override println behavior for reference types

I have a cyclic graph I created using dosync and ref-set. When I pass this to println I get a java.lang.StackOverflowError as I would expect, because it's effectively trying to print an infinitely-nested structure. I found that if I do (str…
Sonicsmooth
  • 2,673
  • 2
  • 22
  • 35
4
votes
1 answer

convert at symbol ("@") to CharSequence

I am testing site with selenium and I need to send an e-mail to one of the fields. So far I am using this Java method: String email = "test@example.com" WebElement emailField =…
Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77
4
votes
1 answer

in kotlin how to change to Array from Array

From one library module it returns some Array>, like below: private val BASIC_ESCAPE_RULE = arrayOf(arrayOf("\"", """), // " arrayOf("&", "&"), arrayOf("<", "<"), arrayOf(">", ">")) fun…
lannyf
  • 9,865
  • 12
  • 70
  • 152
4
votes
1 answer

Convert HashMap.keySet() to CharSequence[]?

I have a method in a client class that gathers data from a server, and returns a HashMap. I want to list the keys in an android dialog. The android API requires that the data must be in in the form of a CharSequence[]. So far as I can tell, there is…
Sean W.
  • 4,944
  • 8
  • 40
  • 66
4
votes
3 answers

Sorting a list of strings based on number of words

I have a file that dumps every line into a position in an ArrayList and I want the user to be able to sort the list to only having lines that have a certain number of words. I can't figure out how to make it print the remaining list (of correct…
dr nips
  • 81
  • 1
  • 9
4
votes
1 answer

How to verify whether an instance of CharSequence is a sequence of Unicode scalar values?

I have an instance of java.lang.CharSequence. I need to determine whether this instance is a sequence of Unicode scalar values (that is, whether the instance is in UTF-16 encoding form). Despite the assurances of java.lang.String, a Java string is…
Nathan Ryan
  • 12,893
  • 4
  • 26
  • 37
3
votes
3 answers

Is there a class in java similar to StringBuilder with the only difference that it has a fixed length?

Something like this: MyFixedLengthStringBuilder sb = new MyFixedLengthStringBuilder(2); sb.append("123"); // <=== throws ArrayIndexOfOutBoundsException! The rest would be exactly the same. Basically I need a StringBuilder that can never grow. I see…
1
2
3
9 10