MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3,

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Review Generics and the ArrayList Class
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
OO Programming Objectives for today: Casting Objects Introduction to Vectors The instanceof keyword.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Programming with Collections Collections in Java Using Arrays Week 9.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
Using ArrayList. Lecture Objectives To understand the foundations behind the ArrayList class Explore some of the methods of the ArrayList class.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
Chapter Eight: Arrays 1.Terms and what they mean 2.Types of arrays -One Dimensional arrays -Two Dimensional arrays -ragged arrays -Parallel arrays 3. Methods.
JAVA 1.5 New Features Dr V. The syntax of the enhanced for loop (for each) for (type variableName : arrayName) { statements } arrayName could be any.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
Programming With Java ICS201 University Of Ha’il1 Chapter 14 Generics and The ArrayList Class.
1 ArrayList  Array’s are limited because we need to know the size before we use them.  An ArrayList is an extension of an array that grows and shrinks.
AP CS Workshop ArrayList It is very common for applications to require us to store a large amount of data. Array lists store large amounts of data.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Arrays. Arrays in Java  Arrays in Java are objects.  Like all objects are created with the new keyword.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type.
Java SE 8 for Programmers, Third Edition
CSE 143 Lecture 4 ArrayList Reading: 10.1 slides created by Marty Stepp
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Computer Science 209 Software Development Java Collections.
Arrays Construct array: new double[10] Store in variable of type double[] double[] data = new double[10];
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Copyright 2008 by Pearson Education Building Java Programs ArrayList Reading: 10.1.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
ArrayList By Neil Butcher. What is the difference between an ArrayList and an Array? An ArrayList is in many ways similar to an array, but has a few subtle.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Thomas Kuehne.
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 1 ArrayLists Section 9.9.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
1 Wrapper Classes  Sometimes we want to use a primitive type as an object, so there are wrapper classes that will help us.  In particular, we need to.
ArrayList JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
JAC444: Intro to Java Arrays and Vectors Tim McKenna
CS1020 Data Structures and Algorithms I Lecture Note #6 Vector and ArrayList.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 GEORGE KOUTSOGIANNAKIS Copyright: 2016 Illinois Institute of Technology/George Koutsogiannakis 1.
Quiz: Design a Product Class Create a definition for a class called Product, which keeps track of the following information: –Name of the product –Weight.
CSE 143 Lecture 3 Implementing ArrayIntList reading: slides created by Marty Stepp and Hélène Martin
Introduction to programming in java Lecture 21 Arrays – Part 1.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Lecture 23:More on Interfaces
Programming in Java Lecture 11: ArrayList
Lists in Python.
ArrayList Collections.
ArrayLists.
Object Oriented Programming in java
Choose the best answer for each problem.
Grouped Data Arrays, and Array Lists.
slides created by Ethan Apter
ArrayLists 22-Feb-19.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
ArrayList.
ArrayLists Readings: 10.1 (pg. 559 – 571).
More on iterations using
Java Coding 6 David Davenport Computer Eng. Dept.,
What can you put into an ArrayList?
Presentation transcript:

MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3, "boat"); b)recVehicles.add(2, "boat"); c)recVehicles.set("boat", 2); d)recVehicles.add("boat", 3); 1 Correct Answer = B Position 3 = index 2 public void add(int index,E element) public E set(int index, E element)

MCQ Which of the following statements correctly stores the value that is the 5th element in an ArrayList of integers, intArrList, into integer variable currNum? a)currNum = intArrList.get(5); b)currNum = intArrList[4]; c)currNum = intArrList.get(4); d)currNum = intArrList.elementAt(4); 2 Correct Answer = c 5 th element = index 4 get(int index)

MCQ Which of the following is used to obtain the size of a String (i.e. number of characters)? a) size() b) length c) length() d) capacity Correct Answer = C str.length() 3

MCQ Which of the following is used to obtain the size of an array? a) size() b) length c) length() d) capacity Correct Answer = B array.length 4

MCQ Which of these method of ArrayList class is used to obtain present size of an ArrayList object? a) size() b) length() c) index() d) capacity() 5 Correct Answer = A list.size()

JAVA API For example: String class Choose java.lang package, select String class ArrayList class Choose java.util package, select ArrayList class Point class Choose java.awt package, select Point class 6