Assume cityList is a type of Listinterface. What will print after the following
ID: 3882136 • Letter: A
Question
Assume cityList is a type of Listinterface. What will print after the following statements are executed system,out.printin(cityList.isEmpty )): cityList.add ("burbank") cityList.add ("carlsbad") a cityList.add ("davis") citylist.add ("granada") ; cityList.add ("sacramento") cityList.add (2, hayward") citylist.add ("nenlo park"): cityList.add (4, "napa"): System.out.printin (cityList.isEmpty O) system.out.printin (cityList.getlength 0) a System.out.println (cityList.getEntry (2) system.out.println (cityList.remove (2) system.out.println (cityList.getEntry (2)) System.out.println (cityList.remove (1)) system.out.println(cityList.remove (2) ) System.out.println(cityList.remove (3)) System.out.println(cityList.get Length O): System.out.println(cityList.replace (2, "oakland")): System.out.println (cityList.getEntry (2)): System.oût.printin(cityList.getEntry (3)) cityList.clear ) system.out.printin(cityList.getLength0)Explanation / Answer
The output would be as follows:
true
false
8
hayward
hayward
davis
carlsbad
napa
sacramento
4
granada
oakland
menlo park
0
This is because isEmpty() gives a boolean output of whether the list has elements in it or not.
add() adds elements to the list. When we give an index as parameter to add, it puts the element in that position.
getLength() returns the size of the list or the number of elements in it
getEntry() returns the element which is held in the index number given as parameter
clear() deletes all the elements of the list
remove() deletes the element held in the index location given as parameter
replace() overwrites the element held in the index number given as parameter
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.