Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For what purpose is Android TextUtils used? [closed]

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?

like image 999
androidcodehunter Avatar asked Jul 20 '13 07:07

androidcodehunter


People also ask

Why we use TextUtils in android?

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" . I like the idea, can you add some code for your answer. provide some code for implementation.

What is TextUtils Java?

TextUtils.StringSplitter. An interface for splitting strings according to rules that are opaque to the user of this interface.


2 Answers

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.

like image 128
type-a1pha Avatar answered Sep 19 '22 09:09

type-a1pha


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".

like image 31
shreyas Avatar answered Sep 19 '22 09:09

shreyas