🆕 Free Interactive Selenium, Playwright & API tools — no signup — Start Free Automation Roadmap →
📁
All Topics › Code Snippets

Code Snippets

Runnable Java code examples for testers: arrays, numbers and strings, with output and common mistakes.

124 Articles
123 Beginner
1 Intermediate
Beginner 📅 Jul 14, 2026 👁 56 views

Find the Sum of Each Row in a 2D Array in Java (Step-by-Step)

Learn how to calculate the sum of each row in a Java 2D array using nested loops and streams, with full code examples and jagged array support.

Beginner 📅 Jul 14, 2026 👁 56 views

Find the Sum of All Elements in a 2D Array in Java

Learn how to calculate the sum of all elements in a Java 2D array using nested loops and streams, including jagged array handling.

Beginner 📅 Jul 14, 2026 👁 87 views

Create and Print a 2D Array in Java (Complete Beginner Guide)

Learn how to create, initialize, and print a 2D array in Java using nested loops and Arrays.deepToString(), including jagged arrays.

Beginner 📅 Jul 13, 2026 👁 45 views

Convert an ArrayList to an Array in Java (toArray() Fully Explained)

Learn how to convert an ArrayList to an array in Java using toArray(), the zero-length array idiom, and streams, with full examples

Beginner 📅 Jul 13, 2026 👁 58 views

Convert an Array to an ArrayList in Java

Learn every way to convert an array to an ArrayList in Java, including the Arrays.asList() trap and primitive array gotchas

Beginner 📅 Jul 13, 2026 👁 54 views

Print an Array in Reverse Order Without Reversing It in Java

Learn how to print a Java array in reverse order without modifying the original array, using loops, streams, and ListIterator.

Beginner 📅 Jul 13, 2026 👁 72 views

Find the Majority Element in a Java Array (Boyer-Moore Voting)

Learn how to find the majority element (appearing more than n/2 times) in a Java array using the Boyer-Moore Voting Algorithm, O(1) space

Beginner 📅 Jul 13, 2026 👁 55 views

Check if an Array Is Sorted or Not in Java (Ascending & Descending)

Learn how to check if a Java array is sorted in ascending or descending order using a single pass loop, with full code and edge cases

Beginner 📅 Jul 13, 2026 👁 76 views

Find a Pair with a Given Sum in a Java Array (Two Sum, O(n) Solution)

Learn how to find a pair of elements summing to a target value in a Java array using HashSet and two-pointer techniques, with full code.

Beginner 📅 Jul 13, 2026 👁 47 views

Remove a Specific Element from an Array in Java

Learn how to remove a specific element from a Java array by value or index, using the shift technique and ArrayList conversion.

Beginner 📅 Jul 13, 2026 👁 53 views

Move All Negative Numbers to the Beginning of a Java Array

Learn to move all negative numbers to the beginning of a Java array using two-pointer partitioning, with order-preserving and non-preserving methods

Beginner 📅 Jul 13, 2026 👁 46 views

Move All Zeros to the Beginning of an Array in Java

Learn how to move all zeros to the beginning of a Java array in-place using a reverse two-pointer technique, with full code examples.

Beginner 📅 Jul 13, 2026 👁 43 views

Move All Zeros to the End of an Array in Java

Learn how to move all zeros to the end of a Java array in-place using the two-pointer technique, preserving the order of non-zero elements

Beginner 📅 Jul 13, 2026 👁 61 views

Find the Index of an Element in a Java Array (Linear & Binary Search)

Learn how to find the index of an element in a Java array using linear search, binary search, and streams, with complexity comparisons.

Beginner 📅 Jul 13, 2026 👁 57 views

Rotate an Array to the Right in Java (Reversal Algorithm Guide)

Learn how to rotate a Java array to the right by k positions using the reversal algorithm and extra array method, with full examples

Beginner 📅 Jul 13, 2026 👁 50 views

Rotate an Array to the Left in Java

Learn how to rotate a Java array to the left by k positions using extra array, juggling algorithm, and reversal techniques

Beginner 📅 Jul 13, 2026 👁 77 views

Swap Two Elements in a Java Array (Temp Variable & XOR Methods)

Learn how to swap two elements in a Java array using a temp variable, arithmetic, and XOR, with clear explanations of why each works.

Beginner 📅 Jul 13, 2026 👁 62 views

Replace an Element at a Specific Index in a Java Array

Learn how to replace an element at a specific index in a Java array safely, with validation, examples, and common mistakes to avoid.

Beginner 📅 Jul 13, 2026 👁 72 views

Find Element at a Specific Index in a Java Array (Beginner Guide)

Learn how to access an array element at a specific index in Java, handle out-of-bounds errors safely, and understand zero-based indexing

Beginner 📅 Jul 13, 2026 👁 51 views

Find Common Elements Between Two Arrays in Java (HashSet Method)

Learn how to find common elements between two arrays in Java using HashSet, retainAll(), and nested loops, with complexity comparisons.

View all 124 Code Snippets articles on one page →