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

Nested classes

class ListFormatter.FormattedList

An immutable class containing the result of a list formatting operation. 

Public methods

String format(Collection<?> items)

Format a collection of objects.

String format(Object... items)

Format a list of objects.

ListFormatter.FormattedList formatToValue(Object... items)

Format a list of objects to a FormattedList.

ListFormatter.FormattedList formatToValue(Collection<?> items)

Format a collection of objects to a FormattedList.

static ListFormatter getInstance(Locale locale, ListFormatter.Type type, ListFormatter.Width width)

Create a list formatter that is appropriate for a locale.

static ListFormatter getInstance(ULocale 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.

static ListFormatter getInstance(Locale locale)

Create a list formatter that is appropriate for a locale.

static ListFormatter getInstance(ULocale locale, ListFormatter.Type type, ListFormatter.Width width)

Create a list formatter that is appropriate for a 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 (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

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

formatToValue

Added in API level 33
public ListFormatter.FormattedList formatToValue (Object... items)

Format a list of objects to a FormattedList. You can access the offsets of each element from the FormattedList.

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

Returns
ListFormatter.FormattedList items formatted into a FormattedList

formatToValue

Added in API level 33
public ListFormatter.FormattedList formatToValue (Collection<?> items)

Format a collection of objects to a FormattedList. You can access the offsets of each element from the FormattedList.

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

Returns
ListFormatter.FormattedList items formatted into a FormattedList

getInstance

Added in API level 33
public static ListFormatter getInstance (Locale locale, 
                ListFormatter.Type type, 
                ListFormatter.Width width)

Create a list formatter that is appropriate for a locale.

Parameters
locale Locale: the locale in question.

type ListFormatter.Type

width ListFormatter.Width

Returns
ListFormatter ListFormatter

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 ()

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

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 33
public static ListFormatter getInstance (ULocale locale, 
                ListFormatter.Type type, 
                ListFormatter.Width width)

Create a list formatter that is appropriate for a locale.

Parameters
locale ULocale: the locale in question.

type ListFormatter.Type

width ListFormatter.Width

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.