R
R
reus2017-03-26 02:39:37
Java
reus, 2017-03-26 02:39:37

How to format strings in Java like Python .format?

In general, it is necessary to generate a string (url).
{domen}/all/{city}/{category}/?view=list&page={page}
the string is set by the user (like {domen}, {city}, {page), etc.., but in a different place) and if necessary, the order is {domen}, {city}, {category}. For example, in python there is such a structure:

"{domen}/all/{city}/{category}/?view=list&page={page}"\
    .format(category="категория", domen="домен", city="город", page="2")

I know that in Java 7 there is such a thing
java.text.MessageFormat.format("{0}/all/{1}/{2}/?view=list&page={3}"....

, but requires a clear order of variables.
How can this be done in Java?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OnYourLips, 2017-03-26
@OnYourLips

but requires a clear order of variables
Why is that bad?
This is fine.
But string interpolation, unfortunately, is not in Java.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question