In this example we will show the method to collect garbage in Java.
Source Code
package com.beginner.examples;
public class GC {
public static void main(String[] args){
Runtime run = Runtime.getRuntime();
run.gc(); // collect garbage
System.out.println("OK!");
}
}
Output:
OK!