Android - What's the difference between String and Editable?

7

When making use of the EditText view, I saw that it returns an Editable data type and not a String. And it has different methods like getEditableText() .

What is the main difference between String and this other data type Editable ? I could not EditText return a simple String ?

Full Explained are highly appreciated

    
asked by anonymous 24.02.2018 / 18:49

1 answer

8

There are two main differences

  • Mutability

    Whenever you apply any operation to a String a new one is created, the same does not happen in the Editable where the operation is applied in the current instance.

  • Possibility to add markup objects (markup objects / style).

    Editable markup objects can be added to an Editable to change the appearance / style of the text, such as underlined (UnderlineSpan ), scratched ( StrikethroughSpan ) and bold ( StyleSpan ), enter other .

24.02.2018 / 19:12