Search code examples
javastringintreplaceall

Java in Eclipse, using replaceAll for int int


I'm working on code for a Java project, I currently have replaceAll(String, int) in the code block of public String getDAT(int col, int MULTIPLIER). Eclipse is saying replaceAll is for (String, String) and not (String, int) how I'm trying to use it.

However the only suggestions are to change it to either replace(), replaceFirst(), or to change MULTIPLIER to a String. I can't do the last because it must be an integer. When I change it according to those first two, the error is essentially the same. I'm pretty new to Java so I don't know too much about it.

Here's that code block (ignore ChatColor and ConfigManager, they go with the rest of the code):

public String getDAT(int col, int MULTIPLIER)
  {
    String RESULT = this.LANGUAGE_DATA[this.LANGUAGE][col];
    RESULT = RESULT.replaceAll("%murk%", ChatColor.DARK_GREEN + ConfigManager.Murk() + ChatColor.WHITE);
    if (MULTIPLIER > 0)
      RESULT = RESULT.replaceAll("%mult%", MULTIPLIER);
    return RESULT;
  }

Help! I still don't have a working answer here! I've added String.valueOf(MULTIPLIER); but it changes none of the problems with replaceAll. Is there supposed to be something else added with String.valueOf(MULTIPLIER);?


Solution

  • You can replace MULTIPLIER with one of those:

    (new Integer(MULTIPLIER)).toString()

    Integer.toString(MULTIPLIER)

    String.valueOf(MULTIPLIER)

    MULTIPLIER + ""