subject
Computers and Technology, 02.04.2021 19:20 Kana81

Now let's write the add method for our SimpleArrayList. First, create a SimpleArrayList class with a single public constructor that initializes the list with a passed array of Object references. You should assert that the passed array is not null. Next, implement a getter getValues() which returns the object array that the list uses to store values. (This is purely for testing.) Also implement size() which returns the size of this list as an int. Now write the add method, which takes the position to add at as an int as its first parameter and the Object reference to add as its second. add should add the element to the list, increasing the size by one and shifting elements after the add position backward. You should assert that the passed position is valid for this list. But note that you should allow adding a new item to the end of the existing list. When you are done, here is how your SimpleArrayList class should work: 1 SimpleArrayList list = new SimpleArrayList(new int[] {1,5});
2 System. out. println(Arrays. toString(list. getValues())); // prints {1, 5}
3 System. out. println(list. size()); // prints 2
4 list. add(1, 2);
5 System. out. println(Arrays. toString(list. getValues())); // prints {1, 2, 5}
6 System. out. println(list. size()); // prints 3

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 15:00, MalikaJones
In the blank libreoffice writer document, to start the process of entering a date field into a letter, click on the insert menu. edit menu. file menu. fields menu.
Answers: 3
image
Computers and Technology, 24.06.2019 12:40, kanga06
Match the feature to the network architecture. expensive to set up useful for a small organization easy to track files has a central server inexpensive to set up difficult to track files useful for a large organization does not have a central server client- server network peer-to-peer network
Answers: 3
image
Computers and Technology, 24.06.2019 13:00, CarlosParker99
Think of a spreadsheet as a giant calculator spread of paper chart data collector
Answers: 2
image
Computers and Technology, 24.06.2019 14:30, thelordoftheknowwjo4
In a home that has 120 v service, there is an electric appliance that has a resistance of 12 ohms. how much power will this appliance consume? a. 10 w b. 120 w c 1200 w d. 1440 w
Answers: 1
You know the right answer?
Now let's write the add method for our SimpleArrayList. First, create a SimpleArrayList class with a...

Questions in other subjects:

Konu
Biology, 02.04.2020 02:48