Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Selenium Testing Tools - Third Edition

You're reading from   Learning Selenium Testing Tools - Third Edition Leverage the power of Selenium to build your own real-time test cases from scratch

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781784396497
Length 318 pages
Edition 3rd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Raghavendra Prasad MG Raghavendra Prasad MG
Author Profile Icon Raghavendra Prasad MG
Raghavendra Prasad MG
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Selenium IDE FREE CHAPTER 2. Locators 3. Overview of the Selenium WebDriver 4. Finding Elements 5. Design Patterns 6. Working with WebDriver 7. Automation Framework Development and Building Utilities 8. Mobile Devices 9. Getting Started with the Selenium Grid 10. Advanced User Interactions 11. Working with HTML5 12. Advanced Topics 13. Migrating from Remote Control to WebDriver Automation Prerequisites for Selenium Automation Answers for Self-test Questions Index

Collections


A collection is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data. Typically, they represent data items that form a natural group, such as a poker hand (a collection of cards), a mail folder (a collection of letters), or a telephone directory (a mapping of names to phone numbers).

What is a Collections framework?

A collections framework is a unified architecture for representing and manipulating groups of data as a single unit collection. All collections frameworks consist of the following parts:

  • Interfaces: The Java collections framework interface provides the abstract data type to represent a collection. The root interface of Collections framework hierarchy is java.util.Collection. Some other important interfaces are java.util.List and java.util.Set. All the collections framework interfaces are present in the java.util package.

  • Implementations: These are the core implementations of the collection interfaces. They are reusable data structures to create different types of collections. Some important collection classes are ArrayList, LinkedList, HashSet, and TreeSet.

  • Algorithms: These are the methods that perform useful and reusable common functionalities, such as searching and sorting, on objects that implement collection interfaces. The same method can be used on many different implementations of the appropriate collection interface.

The following list describes the core collection interfaces:

  • The Collection interface is the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired. Some types of collections allow duplicate elements, and others do not. Some are ordered and others are unordered. The Java platform doesn't provide any direct implementations of this interface but provides implementations of more specific sub-interfaces, such as Set and List

  • The Set interface is a collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets, such as the cards comprising a poker hand, the courses making up a student's schedule, or the processes running on a machine.

    Note

    For more information, please go through http://docs.oracle.com/javase/tutorial/collections/intro/.

    Following is an example code on Collections:

    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    
    public class SetCollection {
      public static void main(String args[]) {
        //Create a set
        Set<String> uniqueSet = new HashSet<String>();
        // Add an elements to set
        uniqueSet.add("Apple");
        uniqueSet.add("Cat");
        uniqueSet.add("Apple");
        uniqueSet.add("Ball");
        
        //Print an elements of the Set
        System.out.println("UniqueSet: " + uniqueSet);
        
        //Retrieve element from set using Iterator
        Iterator<String> iterator = uniqueSet.iterator();
        while (iterator.hasNext()) {
          System.out.println("Iterator: " + iterator.next());
        }
      }
    }

    The output will be as follows:

    UniqueSet: [Ball, Cat, Apple]
    Iterator: Ball
    Iterator: Cat
    Iterator: Apple
    
  • List: This is an ordered collection (sometimes called a sequence). Lists can contain duplicate elements. The user of a list generally has precise control over where in the list each element is inserted and can access elements by their integer index (position). The following is an example of code on lists:

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    public class ListCollection {
      public static void main(String args[]) {
        //Create a List
        List<String> list = new ArrayList<String>();
        // Add an elements to List
        list.add("Apple");
        list.add("Cat");
        list.add("Apple");
        list.add("Ball");
        
        //Print an elements of the List
        System.out.println("List: " + list);
        
        //Retrieve element from list using Iterator
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
          System.out.println("Iterator: " + iterator.next());
        }
      }
    }

    The output will be as follows:

    List: [Apple, Cat, Apple, Ball]
    Iterator: Apple
    Iterator: Cat
    Iterator: Apple
    Iterator: Ball
    
  • SortedSet: This is a set that maintains its elements in an ascending order. Several additional operations are provided to take advantage of the ordering. Sorted sets are used for naturally ordered sets, such as word lists and membership rolls. The following is an example of SortedSet:

    import java.util.Iterator;
    import java.util.SortedSet;
    import java.util.TreeSet;
    
    public class SortedSetCollection {
      public static void main(String args[]) {
        //Create a set
        SortedSet<String> sortSet = new TreeSet<String>();
        // Add an elements to set
        sortSet.add("Apple");
        sortSet.add("Cat");
        sortSet.add("Apple");
        sortSet.add("Ball");
        
        //Print an elements of the Set
        System.out.println("UniqueSet: " + sortSet);
        
        //Retrieve element from set using Iterator
        Iterator<String> iterator = sortSet.iterator();
        while (iterator.hasNext()) {
          System.out.println("Iterator: " + iterator.next());
        }
      }
    }

    The output will be as follows:

    SortedSet: [Apple, Ball, Cat]
    Iterator: Apple
    Iterator: Ball
    Iterator: Cat
    

Note

Following is a reference link for the Collection framework:

http://docs.oracle.com/javase/tutorial/collections/intro/

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images