Java Reference
In-Depth Information
List<String> list =
Arrays.asList( "yellow" , "red" , "green" , "blue" );
Collections.reverse(list);
System.out.println(list);
List<String> list1 =
Arrays.asList( "yellow" , "red" , "green" , "blue" );
List<String> list2 = Arrays.asList( "white" , "black" );
Collections.copy(list1, list2);
System.out.println(list1);
Collection<String> c1 = Arrays.asList( "red" , "cyan" );
Collection<String> c2 = Arrays.asList( "red" , "blue" );
Collection<String> c3 = Arrays.asList( "pink" , "tan" );
System.out.println(Collections.disjoint(c1, c2));
System.out.println(Collections.disjoint(c1, c3));
Collection<String> collection =
Arrays.asList( "red" , "cyan" , "red" );
System.out.println(Collections.frequency(collection, "red" ));
}
}
20.20
Which method can you use to sort the elements in an ArrayList or a LinkedList ?
Which method can you use to sort an array of strings?
20.21
Which method can you use to perform binary search for elements in an ArrayList
or a LinkedList ? Which method can you use to perform binary search for an array
of strings?
20.22
Write a statement to find the largest element in an array of comparable objects.
20.7 Case Study: Bouncing Balls
This section presents a program that displays bouncing balls and enables the user to
add and remove balls.
Key
Point
Section 15.12 presents a program that displays one bouncing ball. This section presents a pro-
gram that displays multiple bouncing balls. You can use two buttons to suspend and resume
the movement of the balls, a scroll bar to control the ball speed, and the
+
or
-
button add or
remove a ball, as shown in Figure 20.8.
F IGURE 20.8
Pressing the
+
or
-
button adds or removes a ball.
The example in Section 15.12 only had to store one ball. How do you store the multiple balls
in this example? The Pane 's getChildren() method returns an ObservableList<Node> , a
subtype of List<Node> , for storing the nodes in the pane. Initially, the list is empty. When a new
ball is created, add it to the end of the list. To remove a ball, simply remove the last one in the list.
 
 
 
Search WWH ::




Custom Search