Skip to main content

C212 - Western Governors University, Indiana - C212; Marketing

Page 1

C212 JAVA FINAL EXAM [IU] Collection - correct answer A ______ is the *grouping together of elements, useful for organizing and retrieving.* examples: Lists, Sets, Maps, Stacks

List - correct answer A ____ is *a collection that remembers the **order** of its elements.* - *necessary for order*

Set - correct answer A ___ is *a collection of **non-ordered unique** elements.* - *Not ordered but all unique**

Map, Key, Value - correct answer A ____ is a collection that *keeps associations between ______ (stored as sets) and ______(stored as lists) objects.

Linked List - correct answer A ____ ___ is *a list of nodes that stores information in reference to neighboring nodes.*

[ Tom ] <—> [ Diana ] <—> [ Harry ]

_______<String> list = new _______<>(); list.addLast("Harry"); list.addFirst("Sally");

List Iterator - correct answer A ___ ___ is *used to access elements inside a linked list.*

By using a position within the list, the ____ ____ points between two elements.

LinkedList<String> employees ...


________<String> example = employees.______();

Linked List, Neighboring, Overhead, Single - correct answer *Why do linked lists take more storage space than arrays of the same size?*

(1) A _____ _____ has to store ___________ nodes. (2) There is ________ for storing an object. In a linked list each node is a separate object that incurs its own overhead, whereas an array is a ______ object.

Integer Index - correct answer Why don't we need iterators with arrays? - Because arrays have _____ _______(s) [i].

Set Interface - correct answer What do hashSet and threeSet have in common? - They both implement the _____ _______. - These arrange the elements so that they can locate them quickly.

LinkedList, ListIterator, iterator - correct answer A loop that removes all strings < 4 from a linked list, words. *define list:* ____a____<String> words = new ____a____<>(); *define iterator:* ___b___<String> iter = words.___c_____(); *Loop:* while ( iter.hasNext() ) { String str = iter.next(); if (str.length() < 4) { iter.remove(); } }

Prints every second element. - correct answer For a linked list of strings, what does this code do? ListIterator<String> myIter = words.iterator(); while( myIter.hasNext() ){ System.out.println( myIter.next() );


if( myIter.hasNext() ) { myIter.next(); } }

Cannot, Ordering, Method - correct answer Can you add an element to a set at an iterator position?

- *You _______ add an elements to a set at an iterator position.*

-Why? (1) *Sets do not have ________*. (2) The *iterator interace has no "add" ________*, unlike the ListInterator. It makes no sense to add elements at a particular position anyway because the set will reorder the elements the way it likes. Thus you can always add elements to a set, but never to an iterator of the set.

Arrays, Lists, Sets - correct answer Differences: - *While _____ and ______ remember the order in which you add elements, ______ do not.*

Set, Efficient - correct answer What to use: a set or array / list? - *A _____ is most _______ for adding and removing elements* as well as *testing for memberships*.

Set, Forward, List - correct answer Why are set iterators different than list iterators? - *With _____ iterator you can move only _______*, but *with _____ Iterator you can move backwards, while also reading the elements.*

Prints all elements that are in both Set<String> s and Set<String> t - correct answer What does this print? for (String str : s ) {


Turn static files into dynamic content formats.

Create a flipbook
C212 - Western Governors University, Indiana - C212; Marketing by AllAcademicsCampus - Issuu