Question 1
To a client, an array and an ArrayList are the same type of object.
True |
False |
Flag this Question
Question 2
In what package is ArrayList found?
java.lang |
java.util |
java.awt |
java.io |
Flag this Question
Question 3
In an ArrayList, what does the size() method tell a client?
How many objects are in the ArrayList |
How much space is left to hold objects in the ArrayList |
The maximum capacity of the ArrayList |
The number of times the add() method has been called |
Flag this Question
Question 4
How many add() methods are in the ArrayList class?
0 |
1 |
2 |
3 |
Flag this Question
Question 5
Both
add(int, E)
set(int, E)
methods put an object into an ArrayList. How do they differ?
The set() method replaces data; the add() method inserts data |
The add() method replaces data; the set() method inserts() data |
Both set() and add() insert the data |
Both set() and add() replace data |
Q1: False; Array are fixed length size, whereas ArrayList are resizable
Q2: java.util
Q3: size() returns the how many objects are in the ArrayList
Q4: There are two add() methods in the ArrayList class
Q5: set() methods replaces the element at a particular index,
whereas add() inserts an element in that index, the elements are
shifted, so correct answer The set() method replaces data; the
add() method inserts data
Question 1 To a client, an array and an ArrayList are the same type of object....
Java Task 2: Write a program where you create an ArrayList object that can store letters. Show how can you add a letter to the ArrayList, remove a letter from theArrayList, replace a letter in the ArrayList, insert a letter in a specific location in the ArrayList, and display all the letters in the ArrayList. Task 3: Write a program where you create an ArrayList object that can store Circle object (you created circle class in your previous PAs). Create...
iii.print out the arraylist iv.reverse all the elements v.print
out this arraylist vi.make a clone of the arraylist
vii.remove all the elements at any odd index of the original
arraylist (not the cloned one)
viii.print out the original arraylist ix.reverse the cloned
arraylist x.print out the cloned arraylist (this arraylist should
still contain the original sequence of elements in order)
xi.merge the cloned arraylist to the original arraylist (please
think about what happens and draw a diagram for yourself to...
10.3 Example. When you first declare a new list, it is empty and its length is zero. If you add three objects—a, b, and c—one at a time and in the order given, to the end of the list, the list will appear as a b c The object a is first, at position 1, b is at position 2, and c is last at position 3.1 To save space here, we will sometimes write a list’s contents on one...
Given a class called Student and a class called Course that
contains an ArrayList of Student. Write a method called
getDeansList() as described below. Refer to Student.java below to
learn what methods are available.
I will paste both of the simple .JAVA codes below
COURSE.JAVA
import java.util.*;
import java.io.*;
/******************************************************
* A list of students in a course
*****************************************************/
public class Course{
/** collection of Students */
private ArrayList<Student> roster;
/*****************************************************
Constructor for objects of class Course
*****************************************************/...
The purpose of this is to use inheritance, polymorphism, object
comparison, sorting, reading binary files, and writing binary
files. In this application you will modify a previous project. The
previous project created a hierarchy of classes modeling a company
that produces and sells parts. Some of the parts were purchased and
resold. These were modeled by the PurchasedPart class. Some of the
parts were manufactured and sold. These were modeled by the
ManufacturedPart class. In this you will add a...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which...
Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to develop some basic skills. Let's start with the code below: The main method imports java.utii.ArrayList and creates an ArrayList that can hold strings by using the new command along with the ArrayList default constructor. It also prints out the ArrayList and, when it does, we see that...
Your text has an example of LinkedList class. Convert the class so that the Link objects have a single long instance variable -- call it "data" -- and the Link instance variable.. Step 2 Then add the following capabilities to the class. A constructor that takes an array of longs as an argument. The contents of the array are use to create Link objects that become objects in the LinkedList. A "search" method that takes a long argument and returns...
1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...
What if you had to write a program that would keep track of a
list of rectangles? This might be for a house painter to use in
calculating square footage of walls that need paint, or for an
advertising agency to keep track of the space available on
billboards.
The first step would be to define a class where one object
represents one rectangle's length and width. Once we have class
Rectangle, then we can make as many objects of...