课程: Java: Data Structures

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Understanding arrays

Understanding arrays

- [Instructor] One of the simplest data structures in Java, and other languages too, is the array. Arrays are objects that contain a fixed number of elements of the same type. So when you create an array, you have to say upfront how many elements are going to be in it. If you change your mind later and decide you want to add some extra elements, you can't just make it bigger, you'd have to create a whole new array. Arrays can contain pretty much any type of value from primitive types like int and double, to object types like string or our own custom types. Every element in the array has to be the same type. So for example, you couldn't have an array where the first element is an int and the second element is a string, that wouldn't be allowed. Arrays are indexed, and they start at zero. So the index of the first element in the array is zero. And the index of the last element in the array is the length of the array minus…

内容