Java Utililty Methods Memory Format

List of utility methods to do Memory Format

  1. HOME
  2. Java
  3. M
  4. Memory Format

Description

The list of methods to do Memory Format are organized into topic(s).

Method

String formatMemory(Integer memory)
format Memory
return String.format("%-9s", String.format("%dM", memory));
String formatMemory(long mem)
format Memory
long kb = mem / 1024;
long mb = kb / 1024;
if (mb > 0)
 return mb + " MB";
else if (kb > 0)
 return kb + " KB";
else
 return mem + " B";
...
String formatMemorySize(long arg)
Format a memory size with g/m/k quantifiers into its number representation.
if (arg >= 1024 * 1024 * 1024)
 return String.format("%d GB", arg / (1024 * 1024 * 1024));
else if (arg >= 1024 * 1024)
 return String.format("%d MB", arg / (1024 * 1024));
else if (arg >= 1024)
 return String.format("%d KB", arg / (1024));
else
 return String.format("%d", arg);
...

AltStyle によって変換されたページ (->オリジナル) /