public static String memoryUsage(){
  final Runtime runtime=Runtime.getRuntime();
  runtime.gc();
  final long max=runtime.maxMemory();
  final long total=runtime.totalMemory();
  final long free=runtime.freeMemory();
  final long used=total - free;
  return String.format("%d\t%d\t%d\t%d",max,total,free,used);
}

public static String memoryUsage ( ) { final Runtime runtime = Runtime . getRuntime ( ) ; runtime . gc ( ) ; final long max = runtime . maxMemory ( ) ; final long total = runtime . totalMemory ( ) ; final long free = runtime . freeMemory ( ) ; final long used = total - free ; return String . format ( "%d\t%d\t%d\t%d" , max , total , free , used ) ; }
calculates the memory usage according to runtime .
