How do you convert CharSequence to String in Android?

Answer

The CharacterSequence is an interface as defined below

// Compiled from CharSequence.java (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;