Lecture Java programming language: Arrays - Ho Dac Hung

Lecture Java programming language: Arrays introduces content such as declaring arrays, using arrays, array parameters, array parameters, searching an array, two-demensional arrays, the arraylist class | Arrays Ho Dac Hung 1 Declaring Arrays An array is a structure that can store many of the same kind of data together at once. Arrays are important and useful programming concept because they allow a collection of related values to be stored together with a single descriptive name. 2 Declaring Arrays An array has a fixed length and can contain only as many data items as its length allows. 3 Declaring Arrays An array element in one of the data items in an array. Each element has an index value with 0 being the index of the first item 1 the index of the second item and so on. An array must be declared and then space allocated for the elements of the array. new 4 Declaring Arrays If the size of the array is known when the application is written then the array can be created and space allocated for thr elements in one statement. new When space has been allocated for the elements of an array the array is initialized to the default values for that element types. 5 Declaring Arrays A third way to create an array is to initialize it in the declaration. Initializing an array means that a value is given for each element. In this case the length of the array is determined by the number of elements between the curly braces. 6 Using Arrays An array element is accessed by including its index in brackets after the array name. An array element id changed throught assignment. A runtime error is generated when an invalid index is used. 7 Using Arrays The array structure includes the length attribute which can be used at run time to determine the length of an array. A for statement is often used to access the elements of an array because the loop control variable can be used as the array index. 8 Array Parameters A method declaration can include array parameters. The array passed to a method can be either an entire array or an element of the array. 9 Characters and Arrays Although strings are comprised of charactersm a String object cannot be manipulated as a set of characters. .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
50    105    3    25-04-2024
97    52    1    25-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.