Found 346 Articles for Java Programming

Java ArrayList to Print all Possible Words from Phone Digits

Neetika Khandelwal
Updated on 22-Aug-2023 17:45:37

158 Views

You are given a keypad of mobile, and the keys that need to be pressed, your task is to print all the words which are possible to generate by pressing these numbers. Input Output Scenarios Let’s go through an example to understand this more: Input str = "32" Output [gd, hd, id, ge, je, ie, gf, hf, if] The characters that can be formed by pressing 3 is g, h, i and by pressing 2 characters d, e, f can be formed. So all the words will be a combination where first character belongs to g, h, ... Read More

Generate a String Consisting of Characters ‘a’ and ‘b’ that Satisfy the given Conditions

Neetika Khandelwal
Updated on 22-Aug-2023 17:43:57

165 Views

The task is to generate a string that consists of characters ‘a’ and ‘b’ which satisfies the condition mentioned below: str must have a length of A+B. The character 'a' must appear A times and the character 'b' must appear B times within the string. The sub−strings "aaa" and "bbb" should not appear in str. After generating the string, it should be printed. One possible solution is to first generate a string with all 'a's and 'b's, with 'a' occurring A times and 'b' occurring B times. Then, we can shuffle the string randomly until we find a ... Read More

How to add an element to an Array in Java?

Shriansh Kumar
Updated on 20-Jul-2023 20:10:49

7K+ Views

Array is a linear data structure that is used to store a group of elements with similar datatypes. It stores data in a sequential manner. Once we create an array we can’t change its size i.e. it is of fixed length. Adding an element to a given array is a vastly common operation. In this article, we will discuss how to add an element to an Array through Java example programs. Adding an element to an Array in Java Let’s understand the operation with an example first − We will add a new element ‘50’ at the end ... Read More

Difference between ArrayList and Vector

Pradeep Kumar
Updated on 19-Apr-2023 17:13:02

1K+ Views

We can store and manage a list of items using the Java Collections Framework classes ArrayList and Vector. Nonetheless, it's crucial to recognise some significant distinctions between the two. We will examine the efficiency, synchronisation, and iterator capabilities of ArrayList and Vector, as well as their similarities and differences, in this tutorial. You will have a comprehensive knowledge of when to utilise ArrayList or Vector in your Java projects by the end of this course. then let's get going! What is an ArrayList? Java's ArrayList class offers an implementation of a dynamic array. It is a resizable array that may ... Read More

How to combine multiple groups to single Test in TestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:59:31

1K+ Views

We can combine multiple groups to single Test in TestNG with the help of test group feature.ExampleTestng xml files with groups.                                                                                                           To run a group of test cases from the collection of test cases, we have to define in the testng xml file. Here the testNG xml contains multiple groups QuestionAnswer and Jobs to be associated to a single Test.Example@Test(groups={"QuestionAnswer"},{"Jobs"}) public void preparation(){    System.out.println("Preparation module is verified"); }In the Java class file the test methods with group as QuestionAnswer and Jobs are associated with the test method preparation().

What do you mean by Listeners in TestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:58:14

428 Views

TestNG Listeners have the capacity to listen to a specific incident. It is basically an interface that changes the nature of the system. TestNG Listeners are used for logging purposes and creating reports.There are two Listeners in Selenium. They are listed below −TestNG Listeners.WebDriver Listeners.TestNG can be configured with the Listeners which can change the default behavior of the TestNG. TestNG Listeners are known as iTestListener (a TestNG interface). A java class implements the iTestListeners and at the same time overrides its methods. Each of these methods trigger an event.The functions of TestNG listeners are listed below.iSuiteListener − This consists ... Read More

How to achieve parallel execution in TestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:54:29

537 Views

We can achieve parallel execution with the help of TestNG. There is a parallel attribute in TestNG which is used for this implementation. The parallel execution in TestNG is associated with another attribute called thread-count.The parallel attribute can have the values listed below −Methods.Classes.InstancesTestsExampleTestng xml file.                                                                           The execution will trigger in parallel mode for tests with the thread count of 5.

What do you mean by timeOut in TestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:52:40

2K+ Views

The timeOut is a helper attribute in TestNG that can put an end to the execution of a test method if that method takes time beyond the timeOut duration. A timeOut time is set in milliseconds, after that the test method will be marked Failed.Example@Test public void ContactVerify(){    System.out.println("Contact validation is successful”); } @Test(timeOut = 1000) public void LandingPage(){    System.out.println("Landing page verification is successful”); } @Test public void LoanContact(){    System.out.println("Loan contact details verification is successful”); }After 1000ms, if LandingPage() execution continues , that test method will be considered as failed. The rest of the test methods will ... Read More

How to incorporate and remove test methods from execution from acollection of test cases in TestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:51:12

235 Views

We can incorporate and remove test methods from execution with the help of tags in testng xml file.ExampleTestng xml file.                                                                                       The testNG xml has groups Smoke to be included and CodingModule to be excluded from the execution.Example@Test(groups={"Smoke"}) public void ContactDetails(){    System.out.println(“Contact details verification is successful”); } @Test(groups={"CodingModule"}) ... Read More

How to execute a particular test method multiple times (say 5 times) inTestNG?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:48:55

523 Views

We can execute a particular test method multiple times (say 5 times) with the help of the invocationCount helper attribute.Example@Test public void PaymentDetails(){    System.out.println("Payment details validation is successful”); } @Test(invocationCount=5) public void LoginAdmin(){    System.out.println("Login in admin is successful”); } @Test public void LeaseDetails(){    System.out.println("Lease details verification is successful”); }In the Java class file, the LoginAdmin() method with invocationCount set to 5 will result in Login in admin is a successful message to be printed five times on the console.

1 2 3 4 5 ... 35 Next
Advertisements