Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

Is there a stopwatch in Java? In google, I find only the code of stopwatches that do not work.

1 Answer

0 votes
by (13.1k points)

You can use org.apache.commons.lang.time.StopWatch. If you are looking for more precision, use System.nanoTime().

Spring also provides a class in the spring-core module

org.springframework.util.StopWatch

You can use it like this:

StopWatch stopWatch = new StopWatch();

stopWatch.start();

// Do something

stopWatch.stop();

System.out.println(stopWatch.getTotalTimeMillis());

Want to learn Java? Check out the core Java certification from Intellipaat.

Related questions

0 votes
1 answer
asked Mar 7, 2021 in Java by Jake (7k points)
0 votes
1 answer

Browse Categories

...