If string is Java is Great! then how can I make it like this:
<font color="red">Java</font> <font color="blue">is</font> <font color="yellow">Great!</font>
The value of color should different for each one.
Similarly, how can I do it for all the words, e.g.
<font color="color1">J</font>
<font color="color2">a</font>
<font color="color3">v</font>
<font color="color4">a</font>
<font color="color5"> </font>
<font color="color6">i</font>
<font color="color6">s</font>
<font color="color7"> </font>
<font color="color8">G</font>
<font color="color9">r</font>
<font color="color10">e</font>
<font color="color11">a</font>
<font color="color12">t</font>
<font color="color13">!</font>
Using different String methods?
To do this you need to access each character in the string one at a time. You can do that by creating a simple loop such as this:
It may be advisable to use a StringBuilder here since you are manipulating a string. Before the loop you can create one lik ethis:
To add the tag around the character in the loop you can do this:
After the loop you will get the new string like this:
And you can do as you please with it. To get the different colors you have to decide how you are keeping those colors, say in an array, and accessing them to build the string appropriately.