Question

I was wondering - "why do others use TextUtils in many purposes?" - but I am not clear about this. The Developer site says that it is a simple string splitter. I understand this but I don't know how to use this in a practical manner or what purposes I can use it? Can anyone provide me some practical example with a code snippet?

Was it helpful?

Solution

It is simply a set of utility functions to do operations on String objects. In fact, the whole class doesn't have any instance fields or methods. Everything is static. Consider it like a container to group functions with a text-based semantic. Many of them could have been methods of a String inherited class or CharSequence inherited class. For example you can do:

TextUtils.indexOf(string, char)

which is the same of doing

string.indexOf(char);

Many of them do things that you can already do with string public methods. Many others add additional functionalities. This class serves at a method level the same purpose that a package serves at a class level.

OTHER TIPS

one of the uses of textUtils is for example lets say you have a string "apple,banana,orange,pinapple,mango" which doesnt fit inside a given width it can be converted to "Apple, banana, 2 more".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top