Wednesday, January 23, 2013

Lab 19d

During lab 19d, we attempted to sort the words by length. We encountered several problems involving the sort() method and making sure that we imported the correct things. Unfortunately, we didn't realize that we could have used the sort method (we didn't have to create our own sort method). I found out later that ArrayList does not have a sort() method. Instead, we use the static sort method of the Collections class. At first, I thought that the sort() method only applies when you want to sort objects by ASCII characters. It was interesting to see that it worked in sorting strings by length. Another problem that we ran into was that we did not import something very important, so our code didn't run at first. We needed to import java.util.Arraylist. Once we dealt these problems, the lab became a lot easier to understand and work out. The sort() method is actually quite useful, and it was interesting to see it actually work in a code.

No comments:

Post a Comment