Class Strings


public final class Strings
This class provides methods to manage and retrieve localized strings from resource bundles. It supports different encodings and allows fetching strings with or without formatting arguments.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if the default resource bundle contains the specified key.
    boolean
    contains(String bundleName, String key)
    Checks if the specified resource bundle contains the specified key.
    get(String key)
    Retrieves the localized string for the specified key from the default resource bundle.
    get(String key, Object... args)
    Retrieves the localized string for the specified key from the default resource bundle, with optional formatting arguments.
    getFrom(String bundleName, String key, Object... args)
    Retrieves the localized string for the specified key from the specified resource bundle, with optional formatting arguments.
    getList(String textFile)
    Get a list of strings from the specified raw text files.
    void
    Sets the character encoding to be used for reading resource bundles.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • setEncoding

      public void setEncoding(Charset charset)
      Sets the character encoding to be used for reading resource bundles.
      Parameters:
      charset - The character encoding to set.
    • get

      public String get(String key)
      Retrieves the localized string for the specified key from the default resource bundle.
      Parameters:
      key - The key for the desired string.
      Returns:
      The localized string corresponding to the specified key, or null if the key is null.
    • get

      public String get(String key, Object... args)
      Retrieves the localized string for the specified key from the default resource bundle, with optional formatting arguments.
      Parameters:
      key - The key for the desired string.
      args - The arguments to format the string with.
      Returns:
      The localized string corresponding to the specified key, formatted with the provided arguments, or null if the key is null.
    • getFrom

      public String getFrom(String bundleName, String key, Object... args)
      Retrieves the localized string for the specified key from the specified resource bundle, with optional formatting arguments.
      Parameters:
      bundleName - The name of the resource bundle to retrieve the string from.
      key - The key for the desired string.
      args - The arguments to format the string with.
      Returns:
      The localized string corresponding to the specified key, formatted with the provided arguments, or the key itself if the resource is not found.
    • getList

      public String[] getList(String textFile)

      Get a list of strings from the specified raw text files. Strings are separated by a new line.

      This method is not cached. Ever call will open up a new InputStream to read the strings from the text file.

      Parameters:
      textFile - The text file that will be retrieved.
      Returns:
      A list with all strings that are contained by the text file.
    • contains

      public boolean contains(String key)
      Checks if the default resource bundle contains the specified key.
      Parameters:
      key - The key to check for.
      Returns:
      True if the key is found in the default resource bundle, false otherwise.
    • contains

      public boolean contains(String bundleName, String key)
      Checks if the specified resource bundle contains the specified key.
      Parameters:
      bundleName - The name of the resource bundle to check.
      key - The key to check for.
      Returns:
      True if the key is found in the specified resource bundle, false otherwise.