Results 1 to 2 of 2
  1. #1
    nikki101 is offline Member
    Join Date
    May 2013
    Rep Power

    Default replacing characteter in string without using replace.

    //function will take string and replace all characters with *
    private static void changingThing(String theString, String chara)
    String theNewString = "";
    String[] theStringArray = new String[] {theString};
    for (int i = 0; i < theString.length(); i++)
    if (theStringArray[i] == "chara")
    theNewString = theNewString + '*';
    theNewString = theNewString + theStringArray[i];
    theString = theNewString;
    Scanner input = new Scanner(;
    System.out.println("String with " + "\'" + chara + "\' " +

    I am not sure where to start. I am a real beginner in java.
    Last edited by nikki101; 05-18-2013 at 04:47 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: replacing characteter in string without using replace.

    Your string array is length of one and contains only one string so you would get an ArrayIndexOutOfBounds exception. Check out the toCharArray method of the String class. If you are having problems, simply experiment with the methods to see what they do before you apply them to solving a problem.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replacing Image for a String
    By vimalaranjan in forum Java 2D
    Replies: 6
    Last Post: 05-04-2011, 06:09 PM
  2. Replacing char in string help
    By jimmy-lin in forum New To Java
    Replies: 3
    Last Post: 10-12-2009, 06:01 AM
  3. Replacing the chars within a string.
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 03-27-2009, 04:00 AM
  4. Help Replacing String
    By 7oclock in forum New To Java
    Replies: 5
    Last Post: 02-14-2009, 07:31 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts