Pravin Gajbhiye
Pravin Gajbhiye

Reputation: 89

How to use subscript in java string?

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

Answers (1)

Andrew
Andrew

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

Related Questions