Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 13 - Maria Litvin, Gary Litvin

Chapter 13 - . In this chapter, the learning objectives are: Learn about interface; learn about the class, its constructors and methods; review some of the ArrayList pitfalls; practice with Part 4 of GridWorld ― “Critters”. | Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld Chapter13 size capacity 13- This chapter also introduces the List interface. Objectives: Learn about interface Learn about the class, its constructors and methods Review some of the ArrayList pitfalls Practice with Part 4 of GridWorld ― “Critters” 13- List and ArrayList are part of the Java Collections Framework (Chapter 20), but other collections are not tested on AP exams. Implements a list using an array Implements interface 13- implements . Another implementation of List is (Chapter 20). cont’d Implements a list using an array. Can only hold objects (of a specified type), not . | Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld Chapter13 size capacity 13- This chapter also introduces the List interface. Objectives: Learn about interface Learn about the class, its constructors and methods Review some of the ArrayList pitfalls Practice with Part 4 of GridWorld ― “Critters” 13- List and ArrayList are part of the Java Collections Framework (Chapter 20), but other collections are not tested on AP exams. Implements a list using an array Implements interface 13- implements . Another implementation of List is (Chapter 20). cont’d Implements a list using an array. Can only hold objects (of a specified type), not elements of primitive data types. Keeps track of the list capacity (the length of the allocated array) and list size (the number of elements currently in the list) "Cat" "Hat" "Bat" capacity size . 13- As opposed to a regular array, ArrayList’s methods check that an index is from 0 to size() - 1, not just from 0 to capacity - 1. ArrayList Generics Starting with Java 5, ArrayList and other collection classes hold objects of a specified data type. The elements’ data type is shown in angle brackets and becomes part of the List and ArrayList type. For example: ArrayList words = new ArrayList(); List nums = new ArrayList(); 13- We would prefer to call them “type-specific collections” rather than “generic collections.” ArrayList Constructors ArrayList ( ) ArrayList (int capacity) Creates an empty ArrayList of default capacity (ten) Java docs use the letter E as the type parameter for elements in generic collections Creates an empty .

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
Đã 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.