Question: I do not know how to create this method, and was wondering if someone could help me do that. We can't use java.array, so we
I do not know how to create this method, and was wondering if someone could help me do that. We can't use java.array, so we have to create this without easier ways to make this. We can only use these two params that are given, so adding is not an option.
boolean add(int index, StringList itemList)
Inserts multiple items into this string list at the specified index position. The relative order of inserted items is preserved. If items were already at that or subsequent positions, then those items are shifted to the right (i.e., itemList.size() is added to their indices).
Instead of inserting items into a string list one at a time, this method enables users to insert multiple items into a string list all at once. Here are some examples:
// first list StringList list1 = new OracleStringList(); list1.add(0, "a"); list1.add(1, "b"); // second list StringList list2 = new OracleStringList(); list2.add(0, "0"); list2.add(1, "1"); // insert second list into first list list1.add(1, list2); System.out.println(list1); // [a, 0, 1, b] // insert modified first list into itself list1.add(1, list1); System.out.println(list1); // [a, a, 0, 1, b, 0, 1, b]
The last code snippet shown above is an example of self-reference; that is, it is a scenario where the source and destination objects are the very same object. This is allowed! Implementers should take special care to avoid accidental infinite loops in situations involving self reference since the size of the source string list may change as items are inserted into the destination string list.
This method should return !itemList.isEmpty() or throw one of its documented exceptions, but never both. It should also support self-reference as described above; that is, a call to this method should still work when itemList refers to the calling string list object itself.
Parameters:
index - index at which the specified items are to be inserted
itemList - string list of items to be inserted
Returns:
true if this list changed as a result of the call
Throws:
NullPointerException - if itemList is null
IndexOutOfBoundsException - if index is out of range (index < 0 || index > size())
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
