Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to fix the length of array in Scala

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to fix the length array in Scala". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to fix the length array in Scala.

1. Fixed length array

How to create a fixed-length array

Use Array to define an array of constant length

Object ArrayDemo {

Def main (args: Array [String]) {

/ / initialize a fixed-length array with a length of 8 and all elements are 0

Val arr1 = new Array [Int] (8)

/ / directly print a fixed-length array containing the hashcode value of the array

Println (arr1)

/ / convert the array to an array buffer, and you can see the contents of the original array.

/ / toBuffer converts arrays to long array buffers

Println (arr1.toBuffer)

/ / Note: if you do not use new to get an array, it is equivalent to calling the apply method of the array and directly assigning values to the array

/ / initialize a fixed-length array with length 1 and value 10

Val arr2 = Array [Int] (10)

/ / output array element values

Println (arr2.toBuffer)

/ / define a fixed-length array of length 3

Val arr3 = Array ("hadoop", "storm", "spark")

/ / use () to access elements

Println (arr3 (2))

/ / an array of 10 integers with an initialization value of 0

Val nums = new Array [Int] (10)

/ / traversing the array

For (I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report