Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in API level 26

ListFormatter

public final class ListFormatter
extends Object

java.lang.Object
   ↳ android.icu.text.ListFormatter


Immutable class for formatting a list, using data from CLDR (or supplied separately). The class is not subclassable.

Summary

Public methods

String format(Object... items)

Format a list of objects.

String format(Collection<?> items)

Format a collection of objects.

static ListFormatter getInstance(ULocale locale)

Create a list formatter that is appropriate for a locale.

static ListFormatter getInstance(Locale locale)

Create a list formatter that is appropriate for a locale.

static ListFormatter getInstance()

Create a list formatter that is appropriate for the default FORMAT locale.

String getPatternForNumItems(int count)

Returns the pattern to use for a particular item count.

Inherited methods

Public methods

format

added in API level 26
public String format (Object... items)

Format a list of objects.

Parameters
items Object: items to format. The toString() method is called on each.

Returns
String items formatted into a string

format

added in API level 26
public String format (Collection<?> items)

Format a collection of objects. The toString() method is called on each.

Parameters
items Collection: items to format. The toString() method is called on each.

Returns
String items formatted into a string

getInstance

added in API level 26
public static ListFormatter getInstance (ULocale locale)

Create a list formatter that is appropriate for a locale.

Parameters
locale ULocale: the locale in question.

Returns
ListFormatter ListFormatter

getInstance

added in API level 26
public static ListFormatter getInstance (Locale locale)

Create a list formatter that is appropriate for a locale.

Parameters
locale Locale: the locale in question.

Returns
ListFormatter ListFormatter

getInstance

added in API level 26
public static ListFormatter getInstance ()

Create a list formatter that is appropriate for the default FORMAT locale.

Returns
ListFormatter ListFormatter

getPatternForNumItems

added in API level 26
public String getPatternForNumItems (int count)

Returns the pattern to use for a particular item count.

Parameters
count int: the item count.

Returns
String the pattern with {0}, {1}, {2}, etc. For English, getPatternForNumItems(3) == "{0}, {1}, and {2}"

Throws
IllegalArgumentException when count is 0 or negative.