What is the Difference between LinkedList and ArrayList in Java?

Here are the differences: 

 ArrayListLinkedList
UsageDynamic ArrayDoubly Linked List
ManipulationNot EfficientEfficient
When to UseBetter to store and fetch dataManipulate Data
Random AccessProvideNot Provide
Memory OverheadLess. Store only object More memory overhead. Store Object and its address

When to use ArrayList and LinkedList in Java?

Here are the use cases: 

ArrayList:

  1. Use when frequent access/modification of elements by index is required.
  2. Suitable for scenarios where elements are added or removed at the end of the list.
  3. Generally preferable for read-heavy operations.
  4. When memory overhead is not a significant concern.
  5. ArrayList provides constant time for search operation, so it is better to use ArrayList if searching is more frequent operation than add and remove operation. 

LinkedList:

  1. Use when frequent insertion/deletion operations are required at the beginning or middle of the list. LinkedList has O(n/2) time complexity to access the elements. ArrayList has O(1) time complexity to access elements via the get and set methods.
  2. Suitable for scenarios where the list structure changes frequently.
  3. When memory overhead can be tolerated, and there's a need for fast insertion/deletion in the middle of the list.
  4. The LinkedList provides constant time for add and remove operations. So it is better to use LinkedList for manipulation.
  5. LinkedLinked class implements Deque interface also, so you can get the functionality of double ended queue in LinkedList. The ArrayList class doesn't implement Deque interface.

What is Difference between ArrayList and Vector in Java?

Here are the differences: 

 ArrayListVector
SynchronisedNoYes
Legacy ClassNoYes
How size increasedArrayList increases its size by 50% of the array sizeVector increases its size by doubling the array size
Thread-SafeNoYes

What are the Basic Interfaces of Java Collections Framework?

Collection framework implements various interfaces, Collection interface and Map interface (java.util.Map) are the mainly used interfaces of Java Collection Framework. List of interfaces of Collection Framework is given below:

  1. Collection Interface
  2. List Interface
  3. Set Interface
  4. Queue Interface
  5. Dequeue Interface
  6. Map Interface

What is the Difference between Array and Collection in Java?

Array and Collection are somewhat similar regarding storing the references of objects and manipulating the data, but they differ in many ways. The main differences between the array and Collection are defined below:

 ArraysCollections
Fixed SizeAlways fixed size. We can not increase or decrease length of array at run time.Can be changed dynamically at run time
Homogeneous or HeterogeneousArrays can store Homogeneous or similar type of objectsHeterogeneous objects can be stored
Types of methodsNot built in methods for sorting and searchingBuilt in methods for sorting and searching 

What is Collection Framework in Java?

Collection Framework is a combination of classes and interface, which is used to store and manipulate the data in the form of objects. 

It provides various classes such as: 

  • ArrayList
  • Vector
  • Stack
  • HashSet, etc. 

and interfaces such as:

  • List
  • Queue
  • Set, etc. 

Why we use static import in REST Assured?

Static imports can be used in REST Assured to simplify code by giving direct access to static methods and fields of a class without explicitly specifying the class name. Static imports are often used in REST Assured to increase test script readability and conciseness.

The static import statements allow us to use methods such as provided(), when(), get(), then(), and matches such as equalTo() and greater-than () without explicitly referencing the class names.

How do you use a REST Assured jsonPath to find all employee IDs between 15 and 300?

Code

Response employeesResponse = RestAssured.given().request(Method.GET, "/all");
JsonPath jsonPathObj = employeesResponse.jsonPath();

//get all employees id between 15 and 300
List<Map> employees = jsonPathObj.get("company.employee
.findAll { employee -> employee.id >= 15 && employee.id <= 300 }");

How to log if Validation Fails in REST Assured?

Since REST Assured 2.3.1 you can log the request or response only if the validation fails. You can log for both request and response.

given().log().ifValidationFails()

 

teststep banner