Package 

Class StringUtil


  • 
    public class StringUtil
    
                        

    Some assorted utility methods for dealing with Strings.

    • Method Summary

      Modifier and Type Method Description
      static boolean isEmpty(String str) Determines if given string is empty or null.
      static String join(List<String> stringsToJoin, String separator) Joins the Strings in the given List together into a single String using the specified separator String.
      static String stringForTime(long milliseconds) Formats the given time duration value (in milliseconds) as a time string in one of the following formats:
      • HH:MM:SS where the timeframe is greater than 1 hour
      • MM:SS where the timeframe is less than an hour
      • M:SS where the timeframe is less than ten minutes
      static String join(Array<String> stringsToJoin, String separator) Joins the Strings in the given array together into a single String using the specified separator String.
      static CharSequence replaceAll(CharSequence template, Array<String> sources, Array<CharSequence> destinations) This method is based on Android's replace and extendsits functionality by replacing all instances of each String specified in the sources parameterwith the associated destination CharSequence.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isEmpty

         static boolean isEmpty(String str)

        Determines if given string is empty or null.

        Parameters:
        str - the String to evaluate
      • join

         static String join(List<String> stringsToJoin, String separator)

        Joins the Strings in the given List together into a single String using the specified separator String.

        Parameters:
        stringsToJoin - the List of Strings to join
        separator - the String to be inserted between each element of the array
      • stringForTime

         static String stringForTime(long milliseconds)

        Formats the given time duration value (in milliseconds) as a time string in one of the following formats:

        • HH:MM:SS where the timeframe is greater than 1 hour
        • MM:SS where the timeframe is less than an hour
        • M:SS where the timeframe is less than ten minutes
        Parameters:
        milliseconds - the time duration to format, in milliseconds
      • join

         static String join(Array<String> stringsToJoin, String separator)

        Joins the Strings in the given array together into a single String using the specified separator String.

        Parameters:
        stringsToJoin - the array of Strings to join
        separator - the String to be inserted between each element of the array
      • replaceAll

         static CharSequence replaceAll(CharSequence template, Array<String> sources, Array<CharSequence> destinations)

        This method is based on Android's replace and extendsits functionality by replacing all instances of each String specified in the sources parameterwith the associated destination CharSequence.It is important to note that this exists for CharSequences (which are not necessarily Strings) that have android.text.Spanned portions and for which the relevant spans must be maintained. If we were to use replaceAll in cases such as these, the span information would be lost.

        Parameters:
        template - the CharSequence on which we should perform replacements
        sources - an Array of Strings to find and replace in template
        destinations - an Array of CharSequences corresponding to the sources strings which will serve as replacements