Let's say i have a String which is like "Hello this is %d next year is %d"
or "I am in %d and we will be in %d"
.
Now I have to replace first %d
with current year and second %d
with next year.
The final String should be
"Hello this is 2021 next year is 2022"
"I am in 2021 and we will be in 2022".
I tried using split and streams, but that didn't really work.
The below approach didnt work
List<String> myList= new ArrayList<>();
myList.add("Hello is %d and %d");
myList.add("Hello this is %d and %d");
for(String s: myList)
{
String.format(s,2021,2022);
System.out.println(s);
}