Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:35:12+00:00 2026-06-11T13:35:12+00:00

If string is Java is Great! then how can I make it like this:

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:35:14+00:00Added an answer on June 11, 2026 at 1:35 pm

    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:

        for(Character c: myString.toCharArray()){
    
        }
    

    It may be advisable to use a StringBuilder here since you are manipulating a string. Before the loop you can create one lik ethis:

       StringBuilder sb = new StringBuilder();
    

    To add the tag around the character in the loop you can do this:

      sb.append("<font color=\"color1\">");
      sb.append(c);
      sb.append("</font>");
    

    After the loop you will get the new string like this:

     String result = sb.toString();
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a Java String with new lines(\n), say for example String value = This
Org-mode has a great feature to include source code like this: #+begin_src java -n
Can someone suggest me some JAVA string library for JAVA ME that includes basic
How can convert a certain file into in a String? And then from that
I have 2 arraylists contained objects like this: 1st arraylist contains string and double
How to print the reverse of the String java is object orientated language without
(ns lol.test (:gen-class :name lol.test :methods [[createHashMap [String] Java.util.HashMap]]) (:import [java.util HashMap])) (defn -createHashMap
Possible Duplicate: Java String.equals versus == I know it' a dumb question but why
Assume two Java String objects: String str = <my string>; String strLower = str.toLowerCase();
Take the following Java string: Hello, World I want to take that string and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.