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

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

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.