Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07.

Similar presentations


Presentation on theme: "Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07."— Presentation transcript:

1 java.util.Vector Brian Toone 10/3/07 Updated 10/10/07

2 What is a Vector object? Think of it as a really convenient array Consider: What if we now want to add a 6 th element? What if we want to check to see if a particular element is contained in the array? What if we want to sort the elements?

3 The nice things about Vector Vector allows you to add elements “on-the-fly” Vector provides a method for automatically searching for a particular element in the array The java.util.Collections class provides a static method for sorting the elements in the array

4 Vector Examples Eclipse Solution to “We are the champions” Solution to “Village People”

5 java.util.Collections The Java Tutorial (Sun), Trail: Collections http://java.sun.com/docs/books/tutorial/collections/index.html Library distributed with latest (> 1.4) versions of the JDK Consists of – Interfaces (Set, List, Queue, Map, SortedSet, SortedMap) – Implementations (HashSet, HashMap, ArrayList, LinkedList) – Algorithms (Sorting, Shuffling, Frequency, Composition) – Vector???

6 Example Algorithm: sort Algorithms provided as static methods in a class called Collections. Simple example: // Add as many elements as we want! Vector v = new Vector (); v.add(35); v.add(85); v.add(22); v.add(99); v.add(68); v.add(73); // Sort the array Collections.sort(v);

7 Example Interface: map Think of this as an associative array Associative arrays are found in some scripting languages such as PHP: $blogTitle = sanitize($_REQUEST['blogTitle']); $blogTags = sanitize($_REQUEST['blogTags']); $blogSummary = sanitize($_REQUEST['blogSummary']); $htmlArea = sanitize($_REQUEST['htmlarea']);

8 Let’s see an example in Java


Download ppt "Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07."

Similar presentations


Ads by Google