Monday, 25 October 2010

Chapter 5 29-33


What are the similarities and differences between a HashSet and an ArrayList?
A:
HashSet is a set of elements that have no duplicate, like a function in mathematics, while ArrayList is simply a list of elements.
The split() method is more powerful than it first seems from our example.
How can you define exactly how a string should be split?
Give some examples.
 A:
The split() method simply takes the parameter of a character which the user specifies in order to tell it where to begin and end the substrings that it will put in the array of Strings. For example if I were to say split(i) for "Hello, I'm Mike", the array would consist of the substrings "Hello, " "'m M" "ke". It actually skips over the character which you specify, another important fact.
How would you call the split() method if you wanted to split a string at either space or tab characters?
How might you break up a string in which the words are separated by colon (':') characters?
 A:
a) split( ) or split((tab key))
b) split(;)
What is the difference in result of returning the words in a HashSet compared with returning them in an ArrayList?
A:
In a HashSet the words are returned by using the HashSet key, while in the ArrayList, the words are returned by stating their index.
What happens if there is more than one space between words (for example: two or three spaces?
Is there a problem?
 A:
My hypothesis is that it would function as normal, for example if the string was "Mike  is  awesome" it would still return "Mike" "is" "awesome".

No comments:

Post a Comment