Java String Pluralize pluralize(int count, String singular, String plural)

Here you can find the source of pluralize(int count, String singular, String plural)

Description

Select singular or plural string based upon count.

License

Open Source License

Parameter

Parameter Description
count The number of items.
singular The output string iif count==1 .
plural The output string iif count!=1 .

Return

Either singular or plural, based upon value of count.

Declaration


public static String pluralize(int count, String singular, String plural) 

Method Source Code

//package com.java2s;
/*   Please see the license information at the end of this file. */

public class Main {
    /**/*from   w w w .j  a  v a 2 s  . co  m*/
     * Select singular or plural string based upon count.
     * 
     * @param count
     *            The number of items.
     * @param singular
     *            The output string iif count==1 .
     * @param plural
     *            The output string iif count!=1 .
     * 
     * @return Either singular or plural, based upon value of count.
     * 
     */

    public static String pluralize(int count, String singular, String plural) {
        return (count == 1) ? singular : plural;
    }

    /**
     * Select singular or plural string based upon count.
     * 
     * @param count
     *            The number of items.
     * @param singular
     *            The output string iif count==1 .
     * @param plural
     *            The output string iif count!=1 .
     * 
     * @return Either singular or plural, based upon value of count.
     * 
     */

    public static String pluralize(long count, String singular, String plural) {
        return (count == 1) ? singular : plural;
    }
}

Related

  1. pluralize(final String s)
  2. pluralize(final String typeName)
  3. pluralize(int count, final String singular, final String plural)
  4. pluralize(int count, String single)
  5. pluralize(int count, String singular)
  6. pluralize(int count, String singular, String plural)
  7. pluralize(int count, String word)
  8. Pluralize(int quantity, String units)
  9. pluralize(int value, CharSequence singularForm, CharSequence pluralForm)