Kotlin byte array init

ByteArray

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

For Native

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.

Читайте также:  Php очистить строку от непечатных символов

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 >> ByteArray . associateByTo (
destination : M ,
keySelector : ( Byte ) -> K ,
valueTransform : ( Byte ) -> 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.

asUByteArray

Returns an array of type UByteArray, 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 Byte >> ByteArray . filterIndexedTo (
destination : C ,
predicate : ( index : Int , Byte ) -> 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 Byte >> ByteArray . filterNotTo (
destination : C ,
predicate : ( Byte ) -> Boolean
) : C

filterTo

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

fun < C : MutableCollection < in Byte >> ByteArray . filterTo (
destination : C ,
predicate : ( Byte ) -> Boolean
) : C

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 >> ByteArray . flatMapIndexedTo (
destination : C ,
transform : ( index : Int , Byte ) -> 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 > ByteArray . foldRightIndexed (
initial : R ,
operation : ( index : Int , Byte , 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.

getCharAt

Gets Char out of the ByteArray byte buffer at specified index index

getDoubleAt

Gets Double out of the ByteArray byte buffer at specified index index

getFloatAt

Gets Float out of the ByteArray byte buffer at specified index index

getIntAt

Gets Int out of the ByteArray byte buffer at specified index index

getLongAt

Gets Long out of the ByteArray byte buffer at specified index index

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.

getShortAt

Gets Short out of the ByteArray byte buffer at specified index index

getUByteAt

Gets UByte out of the ByteArray byte buffer at specified index index

getUIntAt

Gets UInt out of the ByteArray byte buffer at specified index index

getULongAt

Gets ULong out of the ByteArray byte buffer at specified index index

getUShortAt

Gets UShort out of the ByteArray byte buffer at specified index index

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.

fun < K , V > ByteArray . groupBy (
keySelector : ( Byte ) -> K ,
valueTransform : ( Byte ) -> V
) : Map < K , List < V >>

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 < Byte >> > ByteArray . groupByTo (
destination : M ,
keySelector : ( Byte ) -> 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 >> > ByteArray . groupByTo (
destination : M ,
keySelector : ( Byte ) -> K ,
valueTransform : ( Byte ) -> V
) : M

Источник

Kotlin byte array init

kotlin

What is INIT in Kotlin?

Kotlin init The code inside the init block is the first to be executed when the class is instantiated. The init block is run every time the class is instantiated, with any kind of constructor as we shall see next. Multiple initializer blocks can be written in a class. They’ll be executed sequentially as shown below.

What is the difference between init and constructor?

The constructor is called whenever you create a new object. Init method is called when the container loads the servlet for the first time. Init method is called only once when the servlet is loaded. The only similarity between constructer and init method is that they both are called only once.

How do you initialize a constructor in Kotlin?

The primary constructor is initialized in the class header, goes after the class name, using the constructor keyword. The parameters are optional in the primary constructor. The constructor keyword can be omitted if there is no annotations or access modifiers specified.

What is __ init __ In OOP?

The __init__ method is the Python equivalent of the C++ constructor in an object-oriented approach. The __init__ function is called every time an object is created from a class. The __init__ method lets the class initialize the object’s attributes and serves no other purpose. It is only used within classes.

What does __ init __ means?

«__init__» is a reseved method in python classes. It is called as a constructor in object oriented terminology. This method is called when an object is created from a class and it allows the class to initialize the attributes of the class.

Is __ init __ constructor?

What is __init__ in Python? The Default __init__ Constructor in C++ and Java. Constructors are used to initializing the object’s state. The task of constructors is to initialize(assign values) to the data members of the class when an object of the class is created.

What is the point of init?

init is short for initialization. It is a constructor which gets called when you make an instance of the class and it is not necessary. But usually it our practice to write init method for setting default state of the object.

Источник

Оцените статью