Package: java.lang

## Class String

- - ### Methods Summary

    Methods
    Return type | Name and parameters
    --- | ---
    `Object` | `asType(Class c)` Provides a method to perform custom 'dynamic' type conversion to the given class using the `as` operator.
    `String` | `collectReplacements(Closure transform)` Iterate through this String a character at a time collecting either the original character or a transformed replacement String.
    `byte[]` | `decodeBase64()` Decode the String from Base64 into a byte array.
    `byte[]` | `decodeHex()` Decodes a hex string to a byte array.
    `String` | `eachMatch(String regex, Closure closure)` Process each regex group matched substring of the given string.
    `String` | `eachMatch(Pattern pattern, Closure closure)` Process each regex group matched substring of the given pattern.
    `Process` | `execute()` Executes the command specified by `self` as a command-line process.
    `Process` | `execute(String[] envp, File dir)` Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.
    `Process` | `execute(List envp, File dir)` Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.
    `String` | `getAt(IntRange range)` Support the range subscript operator for String with IntRange
    `String` | `getAt(Range range)` Support the range subscript operator for String
    `String` | `getAt(int index)` Support the subscript operator for String.
    `StringBuffer` | `leftShift(Object value)` Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.
    `String` | `plus(CharSequence value)` Appends the String representation of the given operand to this string.
    `int` | `size()` Provide the standard Groovy `size()` method for `String`.
    `Boolean` | `toBoolean()` Converts the given string into a Boolean object.
    `Character` | `toCharacter()` Converts the given string into a Character object using the first character in the string.
    `URI` | `toURI()` Transforms a String representing a URI into a URI object.
    `URL` | `toURL()` Transforms a String representing a URL into a URL object.

  - #### Methods inherited from class java.lang.Object

    `addShutdownHook`, `any`, `any`, `asBoolean`, `asType`, `collect`, `collect`, `collect`, `contains`, `count`, `dump`, `each`, `eachWithIndex`, `equals`, `every`, `every`, `find`, `find`, `findAll`, `findAll`, `findIndexOf`, `findIndexOf`, `findIndexValues`, `findIndexValues`, `findLastIndexOf`, `findLastIndexOf`, `findResult`, `findResult`, `flatten`, `getAt`, `getMetaClass`, `getMetaPropertyValues`, `getProperties`, `grep`, `grep`, `groupBy`, `groupBy`, `hasProperty`, `identity`, `inject`, `inject`, `inspect`, `invokeMethod`, `is`, `isCase`, `iterator`, `join`, `metaClass`, `print`, `print`, `printf`, `printf`, `println`, `println`, `println`, `putAt`, `respondsTo`, `respondsTo`, `setMetaClass`, `size`, `split`, `sprintf`, `sprintf`, `sum`, `sum`, `sum`, `sum`, `toArrayString`, `toSpreadMap`, `toString`, `use`, `use`, `use`, `with`, `withTraits`

  - #### Methods inherited from interface java.lang.CharSequence

    `asBoolean`, `asType`, `bitwiseNegate`, `capitalize`, `center`, `center`, `contains`, `count`, `denormalize`, `drop`, `dropWhile`, `eachLine`, `eachLine`, `eachMatch`, `eachMatch`, `endsWithAny`, `expand`, `expand`, `expandLine`, `find`, `find`, `find`, `find`, `findAll`, `findAll`, `findAll`, `findAll`, `getAt`, `getAt`, `getAt`, `getAt`, `getAt`, `getChars`, `isAllWhitespace`, `isBigDecimal`, `isBigInteger`, `isCase`, `isDouble`, `isFloat`, `isInteger`, `isLong`, `isNumber`, `leftShift`, `matches`, `minus`, `minus`, `multiply`, `next`, `normalize`, `padLeft`, `padLeft`, `padRight`, `padRight`, `plus`, `previous`, `readLines`, `replaceAll`, `replaceAll`, `replaceAll`, `replaceAll`, `replaceFirst`, `replaceFirst`, `replaceFirst`, `replaceFirst`, `reverse`, `size`, `split`, `splitEachLine`, `splitEachLine`, `startsWithAny`, `stripIndent`, `stripIndent`, `stripMargin`, `stripMargin`, `stripMargin`, `take`, `takeWhile`, `toBigDecimal`, `toBigInteger`, `toDouble`, `toFloat`, `toInteger`, `toList`, `toLong`, `toSet`, `toShort`, `toURI`, `toURL`, `tokenize`, `tokenize`, `tokenize`, `tr`, `uncapitalize`, `unexpand`, `unexpand`, `unexpandLine`

  - #### Methods inherited from interface java.lang.Comparable

    `numberAwareCompareTo`

- - ### Methods Detail

    - #### public Object asType(Class c)

      Provides a method to perform custom 'dynamic' type conversion to the given class using the `as` operator. Example: `'123' as Double`

      By default, the following types are supported:

      - List
      - BigDecimal
      - BigInteger
      - Long
      - Integer
      - Short
      - Byte
      - Character
      - Double
      - Float
      - File
      - Subclasses of Enum
      If any other type is given, the call is delegated to DefaultGroovyMethods#asType(Object, Class).
      Parameters:
        `c` - the desired class
      Returns:
        the converted object
      Since:
        1.0

    - #### public String collectReplacements(Closure transform)

      Iterate through this String a character at a time collecting either the original character or a transformed replacement String. The `transform` Closure should return `null` to indicate that no transformation is required for the given character.

          assert "Groovy".collectReplacements{ it == 'o' ? '_O_' : null } == 'Gr_O__O_vy'
          assert "B&W".collectReplacements{ it == '&' ? '&' : null } == 'B&W'

      Parameters:
      Returns:
        A new string in which all characters that require escaping have been replaced with the corresponding replacements as determined by the `transform` Closure.

    - #### public byte[] decodeBase64()

      Decode the String from Base64 into a byte array.

      Returns:
        the decoded bytes as an array
      Since:
        1.0

    - #### public byte[] decodeHex()

      Decodes a hex string to a byte array. The hex string can contain either upper case or lower case letters.

      Returns:
        decoded byte array

    - #### public String eachMatch(String regex, Closure closure)

      Process each regex group matched substring of the given string. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.

      Parameters:
        `regex` - a Regex string
        `closure` - a closure with one parameter or as much parameters as groups
      Returns:
        the source string
      Since:
        1.6.0

    - #### public String eachMatch(Pattern pattern, Closure closure)

      Process each regex group matched substring of the given pattern. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.

      Parameters:
        `pattern` - a regex Pattern
        `closure` - a closure with one parameter or as much parameters as groups
      Returns:
        the source string
      Since:
        1.6.1

    - #### public Process execute()

      Executes the command specified by `self` as a command-line process.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      Returns:
        the Process which has just started for this command line representation
      Since:
        1.0

    - #### public Process execute(String[] envp, File dir)

      Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      Parameters:
        `envp` - an array of Strings, each element of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public Process execute(List envp, File dir)

      Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      Parameters:
        `envp` - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public String getAt(IntRange range)

      Support the range subscript operator for String with IntRange

      Parameters:
        `range` - an IntRange
      Returns:
        the resulting String
      Since:
        1.0

    - #### public String getAt(Range range)

      Support the range subscript operator for String

      Parameters:
        `range` - a Range
      Returns:
        a substring corresponding to the Range
      Since:
        1.0

    - #### public String getAt(int index)

      Support the subscript operator for String.

      Parameters:
        `index` - the index of the Character to get
      Returns:
        the Character at the given index
      Since:
        1.0

    - #### public StringBuffer leftShift(Object value)

      Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.

      Parameters:
        `value` - an Object
      Returns:
        a StringBuffer built from this string
      Since:
        1.0

    - #### public String plus(CharSequence value)

      Appends the String representation of the given operand to this string.

      Parameters:
        `value` - any CharSequence
      Returns:
        the new string with the object appended
      Since:
        2.2

    - #### public int size()

      Provide the standard Groovy `size()` method for `String`.

      Returns:
        the length of the String
      Since:
        1.0

    - #### public Boolean toBoolean()

      Converts the given string into a Boolean object. If the trimmed string is "true", "y" or "1" (ignoring case) then the result is true otherwise it is false.

      Returns:
        The Boolean value
      Since:
        1.0

    - #### public Character toCharacter()

      Converts the given string into a Character object using the first character in the string.

      Returns:
        the first Character
      Since:
        1.0

    - #### public URI toURI()

      Transforms a String representing a URI into a URI object.

      Returns:
        a URI
      Since:
        1.0

    - #### public URL toURL()

      Transforms a String representing a URL into a URL object.

      Returns:
        a URL
      Since:
        1.0