in v ”. No loop is needed. Hint: what methods in v can you call to help you deter-
mine whether x occurs at least twice in v ?
E5. Suppose Vector v has at least two elements. Write a sequence of Java state-
ments to interchange or swap v and v . Test the sequence.
E6. This exercise requires a loop or recursion. Suppose Vector v contains only
elements of class Integer . Write a function that yields the sum of the elements.
E7. This exercise requires a loop or recursion. Write and test a function with a
Vector argument v that produces a string containing the values of the elements
of v in reverse order, separated by commas and delimited by "[" and "]" . This
is what v.toString() produces, but with the elements in the reverse order.
E8. This exercise requires a loop or recursion. Write and test a procedure that
removes from its Vector argument all elements that are not of class Integer .
E9. This exercise requires a loop or recursion. Write and test a procedure with a
Vector argument v that produces a new Vector whose elements are those of v
but with every element duplicated. For example, if v contains ["xy", "xx"] , the
function produces a Vector consisting of: ["xy", "xy", "xx", "xx"] .
Class Date , in package java.util , is useful when you would like to obtain the
current time in your program. Execution of
Date d= new Date();
stores in variable d the name of a new Date object that represents the time, in
milliseconds, that has elapsed since 1 January 1970 (Greenwich Mean Time).
From d , you can get the year, month, day, hour, minute, and millisecond. And we
have used it this way in the past. However, there have been changes, and many
of the methods of this class are now deprecated —which means they have “less-
ened in value” because newer ones are now preferred. Below, we quote from the
API spec for class Dat e to show you why they have been deprecated.
Prior to JDK 1.1, class Date had two additional functions. It
allowed the interpretation of dates as year, month, day, hour,
minute, and second values. It also allowed the formatting and
parsing of date strings. Unfortunately, the API for these functions
was not amenable to internationalization. As of JDK 1.1, class
Calendar should be used to convert between dates and time fields
and class DateFormat should be used to format and parse date
strings. The corresponding methods in Date are deprecated.
So, you see that progress in one area (internationalization) caused other
changes. Java is a living, changing language.