From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Store values in simple arrays

Store values in simple arrays - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Store values in simple arrays

- [Instructor] Java offers a number of different ways to create and manage collections of values. You can declare an array using a simple bit of syntax. And you can either explicitly say, "This is the number of items in the array," or you can create the array, and create the items in the array at the same time. Either way, the array is not resizable. That is, you can't add and remove items from it. You can reset the values at particular indexes, but otherwise the size stays the same. I'll add a bit of code right here in my main method. And I'm going to declare an array. This is going to be a collection of string values, so I'll start with the string type, and then I'll follow that with a pair of brackets. And that means, this is an array of strings. I'll name it Colors, and I'll say this is a new string. And then I'll put in the brackets again, and put in the number of items in the array. I now have three slots where I can…

Contents