Page 284 - Cs_withBlue_J_C11_Flipbook
P. 284
11
ARRAYS
Learning Objectives
11.1 Array 11.2 Need for an Array
11.3 Single-Dimensional Array 11.4 Different Operations on a Single-Dimensional Array
11.5 Insertion 11.6 Deletion
11.7 Merging 11.8 Double-Dimensional Array
11.9 Sorting Vs. Searching 11.10 Linear Search Vs. Binary Search
11.11 Bubble Sort Vs. Selection Sort 11.12 Single-Dimensional Array Vs. Double-Dimensional Array
You know that a variable can store one value at a time. Sometimes, the situation occurred that we need to store several
values of a similar type. In that case, we have to declare several variables. To avoid such situations, Java provides the
concept of an array. Java also provides strings to handle the textual information. In this chapter, we will learn about
arrays and strings.
11.1 ARRAY
An array is a collection of data of a similar type. In other words, an array is a group of variables accessed through a
common name. It can store a set of values of any primitive or non-primitive type. It is a composite data type. The
values stored in an array are known as array elements. In an array, the values are stored one after another and each
value has an index starting from 0 which means that the first value is stored at the 0th index, the second value is stored
at the 1st index, and so on. For example,
Array Values/Elements 5 10 8 7 1 6 4 3 11
Index 0 1 2 3 4 5 6 7 8
th
st
In the above example, you can see that value 5 is stored at 0 index, value 10 is stored at the 1 index, and the last
th
value 11 is stored at the 8 index. The number of elements specifies the length of the array. In the above example,
there are nine elements in the array, so the length of the array is 9.
Definition
Arrays can be defined as a set of variables which contains values of same data types having same variable name but
different subscripts required to separate the values. Thus, we can say that an array is a composite data type.
282282 Touchpad Computer Science-XI

