Reputation: 89
How can I write subscript characters in a Java string?
For example, I have to write "CO2"
. How can I move 2
to the bottom of CO
?
Upvotes: 1
Views: 23524
Reputation: 49646
The String
class doesn't provide such operations. But you could use the Unicode Character 'SUBSCRIPT TWO' (U+2082):
final String string = "CO\u2082"; // CO₂
Also, you could create a String
as an HTML snippet. For instance,
final String html = "CO<sub>2</sub>";
Upvotes: 8