In Java there are eight basic data types; which are: byte, short, int, long, float, double, boolean and char.
It could realistically be said that a Java developer’s time is primarily spent using these particular variable types to store, retrieve and manipulate data to complete most programming tasks. However, there are many times that these primitive variables don’t quite suffice and additional data types need to be explored and used instead.
We will evaluate five additional data types that will help improve and add a higher level of productivity to every Java developer’s day to day activities.
The length of an array is fixed upon creation and it is a “container object that holds a set number of values that are of a single type”.
Arrays are very useful for storing many similar items that need to be sorted later on, or grouped together for additional manipulation.
Strings are a “sequence of characters” and are actually Java objects behind the scenes.
Instead of creating an array of chars, it is more productive to use a String data type to store a series of text. Strings have various built in methods to help with character manipulation such as `replace`, `toLowerCase`, `toUpperCase` and `trim` to name a few.
A HashMap is useful for maintaining groupings of key value pairs. It does not automatically sort either the keys or the values so is good for quick data retrieval if a key/hash is already known.
TreeSet is an excellent data type if you need to store and sort data in an ascending order using a Object tree for storage.
Retrieving data out of a TreeSet is very fast and this makes for “an excellent choice when storing large amounts of sorted information that must be found quickly”.
In a LinkedList , each item/node is a separate Object. Each node in the list is made up of two separate items, which are the actual data and the reference to the next node in the list.
The very last node in the list is set to null which indicates the end of a LinkedList.
“Primitive Data Types” (n.d.) – Available from: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html (Accessed on 31st March 2017)
“Class HashMap<K,V>” (n.d.) – Available from: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html (Accessed on 1st April 2017)
“Java Collection Tutorial – Java Sorted Set” (n.d.) – Available from: http://www.java2s.com/Tutorials/Java/Java_Collection/0110__Java_Sorted_Set.htm (Accessed on 1st April 2017)
“Arrays” (n.d.) – Available from: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html (Accessed on 1st April 2017)
“HashMap in Java with Example” (2014) – Available from: http://beginnersbook.com/2013/12/hashmap-in-java-with-example/ (Accessed on 1st April 2017)
“Linked Lists” (2009) – Available from: https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked%20Lists/linked%20lists.html (Accessed on 1st April 2017)