0

So I have a method that outputs to the console

E.g.

public static void printing(){
System.out.println("33.3");
}

When I call this method in main, it should output 33.3 I want to be able to intercept it before it appears on the console so I can manipulate the data and save it to a variable.

So I found this

Redirect console output to string in Java

But I have trouble understanding the concept. How can I save the output as String and not really print anything to the console in the end?

Fenzox
  • 334
  • 4
  • 20
  • Are you looking for String.format(...)? See https://www.baeldung.com/java-string-formatter – Riaan Nel Nov 06 '20 at 07:44
  • 1
    Alternatively, see this post about intercepting System.out - https://stackoverflow.com/questions/17247688/intercept-system-out-and-prepend-date-time-in-java – Riaan Nel Nov 06 '20 at 07:46
  • @RiaanNel No, looking to intercept System.out, thanks for the link, I will check it out – Fenzox Nov 06 '20 at 08:06

0 Answers0