July 28, 2016

SDET Prep: Data Structures: Arrays, Hashmaps and how to implement them in Java.

This blog post is part of a series as I research how to move from Automation Development to being a Software Developer in Test. We covered some basic algorithms, before. These next few posts will deal with data structures, illustrating them with Java. 

As an automation developer, I've been focusing on browser testing with Selenium WebDriver and Java, being able to draw from my decades of experience testing web applications. When it comes to various data structures, I use arrays, lists, arraylists, and the occasional hashmap in my day-to-day work, but that is about it.

A Software Developer in Test (SDET) isn't that far removed from a Software Development Engineer (SDE), relying on data structures and algorithms I once studied as a Computer Sci major back at Bridgewater State. Note: Each link below goes to the respective Harvard University CS50 video, if any.

If you are a manual tester or automated tester and want to shift to software development, Gayle Laakmann McDowell's Cracking the Coding Interview is an excellent summation of all terms listed above. It seems to be a good resource for even Senior developers, who may be far removed from college.

When you are a Software Developer, you are always trying to find the right tool for the job. When we looked at sorting algorithms:

  • insertion sort was quite fast for sorting five or less elements, but O(n ^ 2) after that.
  • mergesort was very quick, O(n log n), but needed a bit of space, O(n), when creating new arrays to do the work. Want it fast, but space be damned? This algorithm might qualify.  
  • quicksort, which we didn't look at yet, is very quick on average, O(n log n), but at its worst can be as bad as insertion sort O(n ^ 2). The good thing it only needs O(log(n)) of space, worse case scenario, no matter how big the set of elements are that need to be sorted. 

See more algorithms at the Big-O Cheatsheet, by Eric Rowell. It also has a selection of the Big-O times of Data Structures.

Let's go over how to use a few of the data structures, starting with the most basic ones:


Need a way to store a lot of data right next to each other in memory? Arrays are small identically-sized blocks of space. Only the same data typed can be stored in each slot in memory, such as int or char. If there are n elements, First space is 0. Last space is (n-1).

Java has a built in Array object with methods we can use to manipulate the array.

  • Declare an integer array, setting the values: int[] myArray = { 1, 2, 3, 4, 5 };
  • Initialize an array of size 5: int[] blankArray = new int[5];
  • Find the first element: myArray[0] 
  • Print out the array size: System.out.println(myArray.length);
  • Print the last element of the array: int indexLast = (myArray.length - 1); System.out.println(unsortedArray[indexLast]);
  • Print the entire array: System.out.println(Arrays.toString(myArray)); 
  • Sort the array: Array.sort(myArray)
  • Search the array using the binary search algorithm: Array.binarySearch(myArray).

If you declared an array of five elements, it will always have five elements, never six. The space is set in stone.

You can also have multidimentional arrays, such as playing tic-tac-toe on a board that is 3 by 3. For that we would initialize a 3 x 3 grid of characters, since we would be using either an "X" or an "O":

  • Declare a board: char[][] ticTacToe = new char[3][3];
  • The top left corner would be the value: ticTacToe[0][0]
  • The middle space would be the value: ticTacToe[1][1]
  • The right bottom corner space would be the value: ticTacToe[3][3]
  • Want to insert an "O" in the middle? ticTacToe[1][1] = 'O'; // Note the single quotes, suitable for single characters

How about setting up a 10 x 10 board of Battleship to track where your ships are: true if they are on the space, false if they are not on the space?

  • Board setup: boolean[][] battleship = new boolean[10][10];

... The idea it is a 10 x 10 array is just an abstraction. It actually is just allocating 100 spaces in memory. But with this data structure we can loop along battleship[x][y] as if it was the grid we imagine.

CS50: Introduction to Arrays (using C++ sourcecode):



Let's make up an example of how a HashMap can be used in Java.

Take the sentence, "The Quick Brown Fox Jumped Over The Lazy Dog". How many 'A's does it have? 'Q's? 'T's?

  • Let's store the sentence into a String, and make sure that everything is lowercase. Oh, and trim off any whitespace. 
  • And for this example, let's pretend that everything is either alphanumeric (A thru Z or 0 thru 9) or whitespace, just to make it a bit more simple. We can use the String object method "toLowerCase()" and "trim()".

Think of a String as a collection of characters. We can convert the String into one long character array by using the method "toCharacterArray()". Then, we can use a foreach loop to go through each character.

... But where would we store the totals of each character? We could easily set up an array of 26, one for each letter in the English language, but there might be space not used. This would be pretty inefficient.

Let's create a Hashmap called "letters". As we go letter by letter through the String sentence (as a character array) we can:

  • Declare the Hashmap to be of type <Character, Integer>.
  • Loop through the entire sentence, character by character.
Check the letters hashmap. Does it countain a 'q'?

  • If so, let's get whatever the count is up to, increment it by 1, then store it in an integer called "newValue".
  • Let's then put that newValue back in the hashmap, using the character by the key.

What? No 'q' in the hashmap?

  • Let's put in the letters hashmap the value of "1" in that character key.

Here's what I just came up with as a solution:

public void test_HashMap(){
    String sentence = "The Quick Brown Fox Jumped Over the Lazy Dog"
    HashMap<Character, Integer> letters = new HashMap<Character, Integer>();
    for (char character : sentence.toCharArray()){
        if (letters.containsKey(character)){
            int newValue = letters.get(character) + 1;
            letters.put(character, newValue);
        } else if (character != ' '){
            letters.put(character, 1);

If we run the test, we get:
 {a=1, b=1, c=1, d=2, e=4, f=1, g=1, h=2, i=1, j=1, k=1, l=1, m=1, n=1, o=4, p=1, q=1, r=2, t=2, u=2, v=1, w=1, x=1, y=1, z=1}  

That is all we have for now when it comes to Software Development. Happy Testing!

-T.J. Maher
Sr. QA Engineer,

// BSCS, MSE, and QA Engineer since Aug. 1996
// Automation developer for [ 1.5 ] years and still counting!
// Check out Adventures in Automation and Like us on Facebook!


priyanka said...

I am impressed by the information that you have on this blog. It shows how well you understand this subject.
data science courses

Anonymous said...

With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money,
360Digitmg data analytics course in hyderabad

renuka said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
360Digitmg best financial -Analytics course- in-Hyderabad

DataScience Specialist said...

I have to search sites with relevant information ,This is a
wonderful blog,These type of blog keeps the users interest in
the website, i am impressed. thank you.
machine learning course in hyderabad

dataexpert said...

Very nice job... Thanks for sharing this amazing and educative blog post! ExcelR Data Scientist Course In Pune

albina N muro said...

thanks for the tips and information..i really appreciate it.. buy cheap instagram likes spread

ek said...

I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…
Data Scientist Courses Super site! I am Loving it!! Will return once more, Im taking your food likewise, Thanks.

Saketh said...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.ExcelR's PMP Certification

dataexpert said...

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. ExcelR Data Scientist Classes In Pune Any way I’ll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

ek said...

Data Analytics course Pune
I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!
Cool stuff you have, and you keep overhaul every one of us.

saketh321 said...

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. ExcelR Data Analytics Course In Pune Any way I’ll be subscribing to your feed and I hope you post again soon. Big thanks for the use

Data Science Hyderabad said...

Nice information on adventures in automation thanks for sharing.
Data Science Course in Hyderabad

Data Science Training said...

Great article found very useful.
Data Science Training in Hyderabad

tejaswini said...

Good effort to make this blog more beautiful and appealing.data science course in malaysia

ek said...

I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
Data Analytics Courses in PuneI am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles.

Data Science training - 360DigiTMG said...

Truly amazing post found to be very impressive while going through this post which describes about the concept of automation. Thanks for sharing and keep posting such an informative content.

360DigiTMG Digital Marketing Course

360digiTMG said...

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
it course

Anonymous said...

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
360DIgiTMG data science training

Cyber Security said...

IT Company
IT Company
IT Company
IT Company
IT Company
IT Company
IT Company
IT Company

Cyber Security said...

IT Company
IT Company
IT Company
IT Company
IT Company
IT Company
IT Company
IT Company

Data Analytics Course said...

It was a wonderful opportunity to visit this type of site and I am happy to hear about it. Thank you very much for giving us the opportunity to have this opportunity.

360DigiTMG Data Analytics Course in Bangalore

360digitmgas said...

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. 360DigiTMG

360digitmgdelhi said...

incredible article!! sharing these kind of articles is the decent one and I trust you will share an article on information science.By giving an organization like 360DigiTMG.it is one the best foundation for doing guaranteed courses
data science courses in delhi

tejaswini said...

I have bookmarked your site since this site contains significant data in it. You rock for keeping incredible stuff. I am a lot of appreciative of this site.
data science course in malaysia

Akanshya said...

Awesome..I read this post so nice and very informative information...thanks for sharing
Data Science Training in Hyderabad
Data Science course in Hyderabad
Data Science coaching in Hyderabad
Data Science Training institute in Hyderabad
Data Science institute in Hyderabad

360DigiTMG Hyderabad said...

I am very enjoying to read your well-written article posts. It seems that you devote a great deal of hard work and time onto your own blog.Learn Tableau Course in Bangalore 360DigiTMG

EXCELR said...

wonderful article. I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. data science courses

Artificial Intelligence Course said...

You actually make it seem like it's really easy with your acting, but I think it's something I think I would never understand. I find that too complicated and extremely broad. I look forward to your next message. I'll try to figure it out!

Artificial Intelligence Course in Bangalore

Data Science said...

Fantastic article and top quality content with very informative information found very useful thanks for sharing.
Data Analytics Course Online

dataanalyticscourse said...

I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
big data analytics courses

360digitmg said...

Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us.
Best Data Science Courses in Hyderabad

EXCELR said...

Nice blog, it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us.data science course in Hyderabad

James said...

First off, data science training helps candidates choose better career paths. data science course in india

data science course said...

I am glad that i found this page ,Thank you for the wonderful and useful posts and articles enjoyed reading it ,i would like to visit again.
Data Science Course in Mumbai

Data Science Course said...

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

Data Science Course in Pune

360digiTMG Training said...

Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily
Data Science Training in Hyderabad

Data Science Training said...

fantastic Blog! I would like to thank you for the efforts you have made in writing this post and the Content shared was useful and informative.
Data Science Training in Bangalore

Data science course institutes in Marthahalli said...

Great post! I must say and thanks for the information.

data scientist course said...

Hi, I have perused the greater part of your posts. This post is presumably where I got the most valuable data for my examination. Much obliged for posting, we can see more on this. Are you mindful of some other sites regarding this matter.
data scientist course

Data Science in Pune said...

Really impressed! Everything is a very open and very clear clarification of the issues. It contains true facts. Your website is very valuable. Thanks for sharing.
Data Science Classes in Pune

Data Science in Bangalore said...

Really impressed! Everything is a very open and very clear clarification of the issues. It contains true facts. Your website is very valuable. Thanks for sharing.
Data Science In Bangalore

Anonymous said...

Liên hệ Aivivu, đặt vé máy bay tham khảo

vé máy bay đi Mỹ khứ hồi

mua vé máy bay từ hàn quốc về việt nam

vé máy bay từ vinh vào sài gòn

dat ve may bay ra ha noi

vé máy bay tphcm đi bình định

Data Science in Pune said...

I will very much appreciate the writer's choice for choosing this excellent article suitable for my topic. Here is a detailed description of the topic of the article that helped me the most.

Data Science Course in Pune

Sunil said...

The demand for Digital Marketing is growing big every day. With more and more users coming online, the demand for digital marketing is expected to grow even further.

Things after this COVID-19, will not be the same as before. Businesses will have to use technology and digital platforms even more to make their business sustain easily.

Digital Marketing Course with Internship at Digital Brolly.

Maneesha said...

I think about it is most required for making more on this get engaged
data scientist training and placement

Pallavi reddy said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
artificial intellingence training in chennai

traininginstitute said...

I am genuinely thankful to the holder of this web page who has shared this wonderful paragraph at at this place
digital marketing courses in hyderabad with placement

Priya Rathod said...

Excellent post gained so much of information, Keep posting like this.
Data Science Training in Hyderabad
Data Science Course in Hyderabad

Digital Marketing Course said...

It's like you understand the topic well, but forgot to include your readers. Maybe you should think about it from several angles.
Digital Marketing Course in Bangalore

technologyforall said...

Join our Online Data Science Course program to analyze data, make effective predictions and gain a better understanding of market trends. Create disruptive business models for the topmost industries as we equip you with a sound business analytical & entrepreneurial ideology, alongside an excellent grasp of marketing strategies and trends.

ideasontrend said...

Very informative post I really like it. Happy to hear about it more.Kurt Russell Red Coat

Anonymous said...

Great blog with great information provided Software Opinions. Please share more blog like this.

Ramesh Sampangi said...

Become a data science expert by joining AI Patasala’s Data Science Course in Hyderabad, where you can learn data science concepts with real-time experience.
Data Science Course Training in Hyderabad
Data Science Course Training Institute in Hyderabad

360DigiTMG said...

It's a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
data science course in hyderabad

Ramesh Sampangi said...

Really an awesome blog. Informative and knowledgeable content. Keep sharing more blogs with us. Thank you.
Data Science Course in Hyderabad

Data Science said...

Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one.
Continue posting. A debt of gratitude is in order for sharing.
data analytics course in kolhapur

360digiTMG.com said...

The web site is lovingly serviced and saved as much as date. So it should be, thanks for sharing this with us. data scientist course in mysore

business analytics course in gorakhpur said...

Fast forward your career with the best Data Analyst Course offered by 360DigiTMG.Gettrained by expert trainers with placement assistance.
<a href="https://360digitmg.com/india/business-analytics-course-in-gorakhpur''>business analytics course in gorakhpur</a>

data science course in lucknow said...

People are impressed with this technology, and the experts have predicted a bright future of data science.
data science course in lucknow

data science course in patna said...

It has increases the importance of the field. If you have also been attracted by the value of data science and want to learn it, you have to understand the basic courses of data science you need to learn to move successfully in the industry.

data science course in patna

Career Programs Excellence said...

Fast forward your career with the best Data Analyst Course offered by 360DigiTMG. Get trained by expert trainers with placement assistance.

Data Science Training in Delhi

Bhuvankumar said...
This comment has been removed by the author.
Data science course said...

The essential element of data science is data itself. Data can be of quantitative or qualitative types.
data science training in patna

Muskan said...

I like your blog. If anyone want also data science so they can learn with Data science training course in Noida.

sivakumar said...

Very informative and interesting article about the different courses that 360DigiTMG provides. This article is so interesting and engaging. As a newcomer in this field, I looked forward to staying ahead of my peers and building a brilliant and rewarding career. I want to thank this website for providing me the adequate guidance. The post contains essential tips, ideas, and tricks that will be helpful for you to get started in this field. As a beginner, you need to sharpen your basics, so 360DigiTMG institution will be the right choice for you as this institution has industry experts and a rigorous course curriculum to teach all the complex and basic techniques of the data science field.data science course in mumbai

data science course fees chennai said...

I want to thank the writer for their sincere efforts. Best Data Science Institute In Chennai With Placement

Digital Arnav said...

Embrace the data revolution and propel your career forward with APTRON Solutions' Data Analytics Course in Noida. Our expert-led, hands-on program equips you with the knowledge and practical skills needed to excel in the dynamic field of data analytics. Join us and take the first step towards a successful and fulfilling career journey. Enroll today and unlock a world of data-driven possibilities.

kousalya said...

Being a data analytics aspirant, this post has been a great help to me. I stumbled upon this article when I was looking for a pathway to become a certified data analyst looking for an accredited data analytics course. This site contains an extraordinary material collection that 360DigiTMG courses.

servicenow training said...

"I really enjoyed reading your post. It was well-written and thought-provoking."

servicenow certification Training

Arshi said...
This comment has been removed by the author.
Arshi said...

Learn the techniques for efficient data analysis by enrolling in our thorough data analyst training programme in Pune.data analysis course in pune

james anderson said...

Thank you for sharing your transition from Automation Development to Software Developer in Test (SDET). The breakdown of data structures, algorithms, and design patterns, coupled with your personal experience, is incredibly insightful and helpful. Looking forward to more in the series
Careless Driving Ticket New Jersey

Alex said...

The timeline for an uncontested divorce in Virginia varies but generally takes a few months. Virginia uncontested divorce timeline Factors such as court processing and agreement negotiations influence the duration. virginia uncontested divorce timeline Consult with a lawyer for specifics.

rudrasa said...


sailaja said...

"Great article, felt good after reading, worth it.
i would like to read more from you.
keep posting more.
also follow Full Stack Development Course In Hyderabad"

rudrasa said...

Solar Panel Installation Services in Hyderabad

5 year Indian visa for UK citizens said...

Your thoughtful analysis has definitely enriched my understanding of these matters. I admire how you've simplified intricate concepts into such compelling content. Your expertise shines through, making your blog an invaluable source for knowledge-seekers. Excited for the next enlightening piece

Saudi Arabia Visa for Switzerland Citizens said...

Absolutely loved this blog post! Your insights were both enlightening and practical. The way you broke down complex concepts into easy-to-understand steps really resonated with me. I can't wait to implement some of your tips in my own projects. Your engaging writing style and thorough research make this a standout read. Looking forward to more of your expert advice. Keep up the fantastic work! 🌟👏📚✨