Kotlin intarray to string

String

Converts the characters in the specified array to a string.

@DeprecatedSinceKotlin("1.4", "1.5") fun String( chars: CharArray, offset: Int, length: Int ): String
fun String( chars: CharArray, offset: Int, length: Int ): String

Converts the characters from a portion of the specified array to a string.

Exceptions

IndexOutOfBoundsException — if either offset or length are less than zero or offset + length is out of chars array bounds.

fun String( bytes: ByteArray, offset: Int, length: Int, charset: Charset ): String

Converts the data from a portion of the specified array of bytes to characters using the specified character set and returns the conversion result as a string.

Parameters

bytes — the source array for the conversion.

offset — the offset in the array of the data to be converted.

length — the number of bytes to be converted.

charset — the character set to use.

fun String(bytes: ByteArray, charset: Charset): String

Converts the data from the specified array of bytes to characters using the specified character set and returns the conversion result as a string.

fun String( bytes: ByteArray, offset: Int, length: Int ): String

Converts the data from a portion of the specified array of bytes to characters using the UTF-8 character set and returns the conversion result as a string.

Parameters

bytes — the source array for the conversion.

offset — the offset in the array of the data to be converted.

length — the number of bytes to be converted.

fun String(bytes: ByteArray): String

Converts the data from the specified array of bytes to characters using the UTF-8 character set and returns the conversion result as a string.

fun String( codePoints: IntArray, offset: Int, length: Int ): String

Converts the code points from a portion of the specified Unicode code point array to a string.

fun String(stringBuffer: StringBuffer): String

Converts the contents of the specified StringBuffer to a string.

fun String(stringBuilder: StringBuilder): String

Converts the contents of the specified StringBuilder to a string.

Kotlin 1.7

Returns the string representation of this regular expression, namely pattern Note that another regular expression constructed from same pattern string

Источник

IntArray

An array of ints. When targeting the JVM, instances of this class are represented as int[] .

Constructors

Creates a new array of the specified size, where each element is calculated by calling the specified init function.

Creates a new array of the specified size, with all elements initialized to zero.

Properties

size

Returns the number of elements in the array.

Functions

get

Returns the array element at the given index. This method can be called using the index operator.

iterator

Creates an iterator over the elements of the array.

set

Sets the element at the given index to the given value. This method can be called using the index operator.

Extension Properties

indices

Returns the range of valid indices for the array.

lastIndex

Returns the last valid index for the array.

Extension Functions

all

Returns true if all elements match the given predicate.

any

Returns true if array has at least one element.

Returns true if at least one element matches the given predicate.

asIterable

Creates an Iterable instance that wraps the original array returning its elements when being iterated.

asSequence

Creates a Sequence instance that wraps the original array returning its elements when being iterated.

associate

Returns a Map containing key-value pairs provided by transform function applied to elements of the given array.

associateBy

Returns a Map containing the elements from the given array indexed by the key returned from keySelector function applied to each element.

Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given array.

associateByTo

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given array and value is the element itself.

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given array.

fun < K , V , M : MutableMap < in K , in V >> IntArray . associateByTo (
destination : M ,
keySelector : ( Int ) -> K ,
valueTransform : ( Int ) -> V
) : M

associateTo

Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given array.

associateWith

Returns a Map where keys are elements from the given array and values are produced by the valueSelector function applied to each element.

associateWithTo

Populates and returns the destination mutable map with key-value pairs for each element of the given array, where key is the element itself and value is provided by the valueSelector function applied to that key.

asUIntArray

Returns an array of type UIntArray, which is a view of this array where each element is an unsigned reinterpretation of the corresponding element of this array.

average

Returns an average value of elements in the array.

binarySearch

Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted, otherwise the result is undefined.

component1

Returns 1st element from the array.

component2

Returns 2nd element from the array.

component3

Returns 3rd element from the array.

component4

Returns 4th element from the array.

component5

Returns 5th element from the array.

contains

Returns true if element is found in the array.

contentEquals

Returns true if the two specified arrays are structurally equal to one another, i.e. contain the same number of the same elements in the same order.

contentHashCode

Returns a hash code based on the contents of this array as if it is List.

contentToString

Returns a string representation of the contents of the specified array as if it is List.

count

Returns the number of elements in this array.

Returns the number of elements matching the given predicate.

distinct

Returns a list containing only distinct elements from the given array.

distinctBy

Returns a list containing only elements from the given array having distinct keys returned by the given selector function.

drop

Returns a list containing all elements except first n elements.

dropLast

Returns a list containing all elements except last n elements.

dropLastWhile

Returns a list containing all elements except last elements that satisfy the given predicate.

dropWhile

Returns a list containing all elements except first elements that satisfy the given predicate.

elementAtOrElse

Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.

elementAtOrNull

Returns an element at the given index or null if the index is out of bounds of this array.

filter

Returns a list containing only elements matching the given predicate.

filterIndexed

Returns a list containing only elements matching the given predicate.

filterIndexedTo

Appends all elements matching the given predicate to the given destination.

fun < C : MutableCollection < in Int >> IntArray . filterIndexedTo (
destination : C ,
predicate : ( index : Int , Int ) -> Boolean
) : C

filterNot

Returns a list containing all elements not matching the given predicate.

filterNotTo

Appends all elements not matching the given predicate to the given destination.

fun < C : MutableCollection < in Int >> IntArray . filterNotTo (
destination : C ,
predicate : ( Int ) -> Boolean
) : C

filterTo

Appends all elements matching the given predicate to the given destination.

find

Returns the first element matching the given predicate, or null if no such element was found.

findLast

Returns the last element matching the given predicate, or null if no such element was found.

first

Returns the first element.

Returns the first element matching the given predicate.

firstOrNull

Returns the first element, or null if the array is empty.

Returns the first element matching the given predicate, or null if element was not found.

flatMap

Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.

flatMapIndexed

Returns a single list of all elements yielded from results of transform function being invoked on each element and its index in the original array.

flatMapIndexedTo

Appends all elements yielded from results of transform function being invoked on each element and its index in the original array, to the given destination.

fun < R , C : MutableCollection < in R >> IntArray . flatMapIndexedTo (
destination : C ,
transform : ( index : Int , Int ) -> Iterable < R >
) : C

flatMapTo

Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.

fold

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

foldIndexed

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element with its index in the original array.

foldRight

Accumulates value starting with initial value and applying operation from right to left to each element and current accumulator value.

foldRightIndexed

Accumulates value starting with initial value and applying operation from right to left to each element with its index in the original array and current accumulator value.

fun < R > IntArray . foldRightIndexed (
initial : R ,
operation : ( index : Int , Int , acc : R ) -> R
) : R

forEach

Performs the given action on each element.

forEachIndexed

Performs the given action on each element, providing sequential index with the element.

getOrElse

Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.

getOrNull

Returns an element at the given index or null if the index is out of bounds of this array.

groupBy

Groups elements of the original array by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.

Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.

groupByTo

Groups elements of the original array by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.

fun < K , M : MutableMap < in K , MutableList < Int >> > IntArray . groupByTo (
destination : M ,
keySelector : ( Int ) -> K
) : M

Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values.

fun < K , V , M : MutableMap < in K , MutableList < V >> > IntArray . groupByTo (
destination : M ,
keySelector : ( Int ) -> K ,
valueTransform : ( Int ) -> V
) : M

Источник

joinToString

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

If the collection could be huge, you can specify a non-negative value of limit, in which case only the first limit elements will be appended, followed by the truncated string (which defaults to «. «).

import kotlin.test.* fun main(args: ArrayString>) < //sampleStart val numbers = listOf(1, 2, 3, 4, 5, 6) println(numbers.joinToString()) // 1, 2, 3, 4, 5, 6 println(numbers.joinToString(prefix = "[", postfix = "]")) // [1, 2, 3, 4, 5, 6] println(numbers.joinToString(prefix = ", postfix = ">", separator = "•")) // val chars = charArrayOf('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q') println(chars.joinToString(limit = 5, truncated = ". ") < it.uppercaseChar().toString() >) // A, B, C, D, E, . //sampleEnd >

Источник

Читайте также:  Java исключение меньше нуля
Оцените статью