Back to the grind. Starting with passing by value lesson in udemy. There’s no passing by reference in java. Think it makes sense but might be worth rewatching the videos 46–52 at some point especially if I need to use anything for an actual project. For now, knowing about the tools is my main concern. Not mastering them… yet.

Now I’m on how to use ArrayList of the collections framework. So the ArrayList is good for keeping a list of items and if you plan to remove the last items of that list. If you will need to remove the first items it will not do so fast and John recommends using a LinkedList which is what I’m learning next.

So LinkedList uses previous index to point to the next index item and that item points back to the previous one as well which makes it fast when adding or removing items from beginning or middle of list. ArrayList is still fast enough to add or remove at end of list.

Next is HashMap which uses key and value pairs much like a dictionary. It does not maintain order. If you want order you must use either a LinkedHashMap or TreeMap. TreeMap sorts is naturally defined order.

A set only stores unique elements. It’s good for getting rid of duplicates. Does not retain order. LinkedHashSet remembers order you added the items to the list. TreeSet sorts in natural order. Sets are GREAT for seeing if the collection contains a particular item. Can find intersection or difference between two sets using .retainAll() or .removeAll() respectively.

When using my own custom objects must generate hashcode and equals if i want them to behave as normal sets and keys in maps.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store