The binary representation of a Text object is a variable-length integer containing the number of bytes in the UTF-8 representation of the string, followed by the UTF-8 bytes themselves.
Text is a replacement for the UTF8 class, which was deprecated because it didn’t support strings whose encoding was over 32,767 bytes and because it used Java’s modified UTF-8.
Furthermore, Text uses standard UTF-8, which makes it potentially easier to interoperate with other tools that understand UTF-8.
Following are some of the differences in brief related to its functioning with respect to String:
Indexing: Because of its emphasis on using standard UTF-8, there are some differences between Text and the Java String class. Indexing for the Text class is in terms of position in the encoded byte sequence, not the Unicode character in the string, or the Java char code unit (as it is for String).
For instance, charAt() returns an int representing a Unicode code point, unlike the String variant that returns a char.
Iteration: Iterating over the Unicode characters in Text is complicated by the use of byte offsets for indexing since you can’t just increment the index.
Mutable: Another difference with String is that Text is mutable (like all Writable implementations in Hadoop, except NullWritable, which is a singleton). You can reuse a Text instance by calling one of the set()methods on it.
Resorting to String: The text doesn’t have as rich an API for manipulating strings as java.lang.String, so in many cases, you need to convert the text object to a String. This is done in the usual way, using the toString()method:
I hope this helps.