Java String Pluralize pluralize(String name)

Here you can find the source of pluralize(String name)

Description

Convert singular name to plural form.

License

Open Source License

Parameter

Parameter Description
name base name

Return

plural name

Declaration

public static String pluralize(String name) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w w w.  jav a2 s. c o m
     * Convert singular name to plural form. TODO: internationalization?
     * 
     * @param name base name
     * @return plural name
     */
    public static String pluralize(String name) {

        // first check for already in plural form
        if (name.endsWith("List") || (name.endsWith("s") && !name.endsWith("ss"))) {
            return name;
        }

        // convert singular form to plural
        if (name.endsWith("y") && !name.endsWith("ay") && !name.endsWith("ey") && !name.endsWith("iy")
                && !name.endsWith("oy") && !name.endsWith("uy")) {
            if (name.equalsIgnoreCase("any")) {
                return name;
            } else {
                return name.substring(0, name.length() - 1) + "ies";
            }
        } else if (name.endsWith("ss")) {
            return name + "es";
        } else {
            return name + 's';
        }
    }
}

Related

  1. pluralize(long val, String singular, String plural)
  2. pluralize(String base, int quantity)
  3. pluralize(String input)
  4. pluralize(String name)
  5. pluralize(String name)
  6. pluralize(String name)
  7. pluralize(String s)
  8. pluralize(String singular, long number)
  9. pluralize(String singularNoun)