Book Image

Hands-On Automation Testing with Java for Beginners

Book Image

Hands-On Automation Testing with Java for Beginners

Overview of this book

Java is one of the most commonly-used software languages by programmers and developers. Are you from a non-technical background and looking to master Java for your automation needs? Then Hands-On Automation Testing with Java for Beginners is for you. This book provides you with efficient techniques to effectively handle Java-related automation projects. You will learn how to handle strings and their functions in Java. As you make your way through the book, you will get to grips with classes and objects, along with their uses. In the concluding chapters, you will learn about the importance of inheritance and exceptions with practical examples. By the end of this book, you will have gained comprehensive knowledge of Java.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell

The Set collection

Another important collection present in Java is the Set collection/interface. HashSet, TreeSet, and LinkedHashSet are the three classes that implement the Set interface. The main difference between Set and List is that Set does not accept duplicate values. One more difference between the Set and List interfaces is that there is no guarantee that elements are stored in sequential order.

We will mainly be discussing HashSet in this section. We will take an example class and try to understand this concept. Create a class and name it hashSetexample for this section, and create an object within the class to use HashSet; it'll suggest you add the argument type, which is String in our case:

package coreJava;

import java.util.HashSet;

public class hashSetexample {

    public static void main(String[] args) {

       HashSet<String> hs= new HashSet<String>();


In your IDE when you type hs., it'll show you all the methods provided by HashSet:

Start by adding a...