tailieunhanh - Lecture An introduction to Object-Oriented Programming with Java - Chapter 10: Arrays

In this chapter we will learn about Java arrays. In Java, an array is an indexed collection of data values of the same type. For example, we can define an array of 10 integers, an array of 15 Student objects, an array of 100 Account objects, and so forth. We are not allowed in Java to create an array of 10 integers and 10 doubles, for example, because the values are of different data types. In this chapter we will learn the basics of array manipulation and how to use different types of arrays properly and effectively. | Chapter 10 Arrays Chapter 10 Objectives After you have read and studied this chapter, you should be able to Manipulate a collection of data values, using an array. Declare and use an array of primitive data types in writing a program. Declare and use an array of objects in writing a program. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 Objectives, cont. After you have read and studied this chapter, you should be able to Define a method that accepts an array as its parameter and a method that returns an array. Describe how a two-dimensional array is implemented as an array of arrays. Manipulate a collection of objects, using lists and maps. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Array Basics In Java, an array is an indexed collection of data values of the same type. Arrays are useful for sorting and manipulating a collection of values. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. Sample array: Monthly rainfall averages and their variation from the annual average. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Array Basics Square brackets [] are used to declare an array. To declare an array, we may attach the brackets to either the data type or the variable name. An array named rainfall of type double, may be stated either as double [] rainfall; or double rainfall []; ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Array Basics In Java, an array is a reference data type. We use the new operator to allocate the memory to store the values in an array. rainfall = new double [12]; //creates an array of size 12. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. An array of 12 double values. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Array Basics We use a single identifier to . | Chapter 10 Arrays Chapter 10 Objectives After you have read and studied this chapter, you should be able to Manipulate a collection of data values, using an array. Declare and use an array of primitive data types in writing a program. Declare and use an array of objects in writing a program. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 Objectives, cont. After you have read and studied this chapter, you should be able to Define a method that accepts an array as its parameter and a method that returns an array. Describe how a two-dimensional array is implemented as an array of arrays. Manipulate a collection of objects, using lists and maps. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Array Basics In Java, an array is an indexed collection of data values of the same type. Arrays are useful for sorting and manipulating a collection of values. ©TheMcGraw-Hill Companies, Inc. Permission required for .

crossorigin="anonymous">
Đã 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.