3

I have the url https://www.someurl.com/v2/path/[PARAM1]?key=[PARAM1]2. I want to do the following

final String URL = "https://www.someurl.com/v2/path/%?key=%";
String val = String.format(URL, "details", "testing");
System.out.println(val);

But I am getting an error

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '?'
at java.util.Formatter.checkText(Formatter.java:2547)
at java.util.Formatter.parse(Formatter.java:2533)
at java.util.Formatter.format(Formatter.java:2469)
at java.util.Formatter.format(Formatter.java:2423)
at java.lang.String.format(String.java:2845)
at split.StringStuff.main(StringStuff.java:22)

How might I make it work?

learner
  • 11,490
  • 26
  • 97
  • 169

2 Answers2

3

Since the placeholders are for String values, you need to use %s instead of just %.

final String URL = "https://www.someurl.com/v2/path/%s?key=%s";
Rahul
  • 44,383
  • 11
  • 84
  • 103
2

you should use %s character in format, not just %.

TechnoCat
  • 25
  • 3