Java String format

The java string format() method returns the formatted string by given locale, format and arguments.

If you don't specify the locale in String.format() method, it uses default locale by calling Locale.getDefault() method

The format() method of java language is like sprintf() function in c language and printf() method of java language


There are two type of string format() method:

public static String format(String format, Object... args)


public static String format(Locale locale, String format, Object... args)


locale : specifies the locale to be applied on the format() method.

format : format of the string.

args : arguments for the format string. It may be zero or more.


formatted string


NullPointerException : if format is null.

IllegalFormatException : if format is illegal or incompatible.

Java String equals() method example

Flash soon

Copyright 2017 Design& Development