Java String Pluralize pluralize(int count, String single)

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

Description

Return the count and the quantity label as a properly pluralized string.

License

Open Source License

Declaration

public static String pluralize(int count, String single) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright (c) 2012 Google, Inc.//from  w  w w  .j ava2  s.  c  om
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors:
 *  Google, Inc. - initial API and implementation
 *******************************************************************************/

import java.text.NumberFormat;

public class Main {
    /**
     * Return the count and the quantity label as a properly pluralized string.
     * I.e. (5, "item") ==> "5 items".
     * <p/>
     * 
     */
    public static String pluralize(int count, String single) {
        if (count == 1) {
            return NumberFormat.getNumberInstance().format(count) + " " + single;
        } else {
            return NumberFormat.getNumberInstance().format(count) + " " + single + "s";
        }
    }
}

Related

  1. pluraliseNoun(String noun, long count, boolean forceAppendingSByDefault)
  2. pluralize(final int count, final String singular, final String plural)
  3. pluralize(final String s)
  4. pluralize(final String typeName)
  5. pluralize(int count, final String singular, final String plural)
  6. pluralize(int count, String singular)
  7. pluralize(int count, String singular, String plural)
  8. pluralize(int count, String singular, String plural)
  9. pluralize(int count, String word)