Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the print method in Kotlin have the same effect as Java

Tags:

kotlin

println

I tried this code below in Kotlin. The print method cache the input data until I call the println method.

>>> print(1)
>>> print(2)
>>> System.out.print(3)
>>> System.out.print(4)
>>> println(5)
12345

I'd like to print the number as a sequence number by number like Java. How could I do that in Kotlin?

Update: Maybe someone misunderstands my question.

I want the print method print the input data immediately instead of waiting for println method.

like image 528
Trần Đức Tâm Avatar asked Nov 16 '25 00:11

Trần Đức Tâm


1 Answers

Call System.out.flush() after print.

print(1)
System.out.flush()
like image 93
gvlasov Avatar answered Nov 17 '25 20:11

gvlasov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!