Timer cancel() in Java

cancel(): This method is available in java.util.Timer class of Java.

Syntax:

void java.util.Timer.cancel()

This method terminates this timer, discarding any currently scheduled tasks. Do not interfere with a currently executing task.

Parameters: NA

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Timer;

public class Timercancel {
    public static void main(String[] args) {

        Timer timer = new Timer();

        System.out.println("Cancel timer");
        timer.cancel();
    }
}

Output:

Cancel timer


No comments:

Post a Comment