Need Help! Contact me.Email me Thank You.

How do you convert CharSequence to String in Android?


The CharacterSequence is an interface as defined below

// Compiled from (version 1.5 : 49.0, no super bit)
public abstract interface java.lang.CharSequence {
  // Method descriptor #4 ()I
  public abstract int length();
  // Method descriptor #6 (I)C
  public abstract char charAt(int arg0);
  // Method descriptor #8 (II)Ljava/lang/CharSequence;
  public abstract java.lang.CharSequence subSequence(int arg0, int arg1);
  // Method descriptor #10 ()Ljava/lang/String;
  public abstract java.lang.String toString();

Now String class implments this interface so you could simple write:

CharSequence in = “some string”;

// then convert CharSequence to String

String s = cs.toString();

If you want to the viceversa String to CharSequence is straight forward too.

String a = “test”;

CharSequence c = a;


Subscribe to DeveloperFeedDid you like this article? Did it Help you Solve your Problem? You can get the all the latest articles published at DeveloperFeed in your email inbox by entering your email address below. Your address will only be used for mailing you the articles, and each one will include a link so you can unsubscribe at any time.