🆕 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.

123 Articles
123 Beginner
1 Intermediate
Beginner 📅 Jul 13, 2026 👁 64 views

Merge Two Arrays in Java (With and Without Sorting)

Learn how to merge two arrays in Java using System.arraycopy(), manual loops, and streams, including sorted-merge techniques.

Beginner 📅 Jul 13, 2026 👁 46 views

Compare Two Arrays for Equality in Java (Arrays.equals() & Beyond)

Learn how to check if two arrays are equal in Java using Arrays.equals(), deepEquals(), and manual loops, including order-sensitive cases.

Beginner 📅 Jul 13, 2026 👁 47 views

Find Sum of Even and Odd Elements Separately in a Java Array

Learn to calculate the sum of even and odd elements separately in a Java array using loops and streams, with full code examples.

Beginner 📅 Jul 13, 2026 👁 39 views

Count Positive and Negative Numbers in a Java Array (Complete Guide)

Learn how to count positive, negative, and zero values in a Java array using loops and streams, including the zero classification rule.

Beginner 📅 Jul 13, 2026 👁 39 views

Separate Even and Odd Elements into Two Arrays in Java

Learn how to split a Java array into separate even and odd element arrays using two-pass counting and dynamic ArrayList methods.

Beginner 📅 Jul 13, 2026 👁 49 views

Count Even and Odd Elements in a Java Array

Learn how to count even and odd elements in a Java array using the modulo operator, with negative number handling and streams.

Beginner 📅 Jul 13, 2026 👁 51 views

Find the First Duplicate Element in a Java Array

Learn how to find the first duplicate element in a Java array in a single pass with HashSet, including the "first by index" nuance

Beginner 📅 Jul 13, 2026 👁 51 views

Find Unique Elements in an Array in Java

Learn how to find elements that appear exactly once in a Java array using HashMap, LinkedHashSet, and the XOR trick for special cases

Beginner 📅 Jul 13, 2026 👁 53 views

Count Frequency of Each Element in an Array in Java (HashMap Guide)

Learn how to count the frequency of each element in a Java array using HashMap, streams, and sorting-based approaches, with examples.

Beginner 📅 Jul 13, 2026 👁 53 views

Remove Duplicates from an Array in Java

Learn how to remove duplicate elements from a Java array using LinkedHashSet, two pointers, and streams while preserving order.

Beginner 📅 Jul 13, 2026 👁 85 views

Reverse an Array in Java (In-Place, Recursive & Stream Methods)

Learn how to reverse an array in Java in-place, recursively, and with streams, complete with memory diagrams, examples, and best practices.

Beginner 📅 Jul 13, 2026 👁 70 views

Sort an Array in Descending Order in Java (3 Practical Methods)

Learn how to sort an array in descending order in Java using manual loops, Collections.reverseOrder(), and streams, with full examples.

Beginner 📅 Jul 13, 2026 👁 82 views

Sort an Array in Ascending Order in Java

Learn how to sort an array in ascending order in Java using bubble sort, Arrays.sort(), and streams, with complexity analysis and examples.

Beginner 📅 Jul 12, 2026 👁 56 views

Find the Difference Between Max and Min in a Java Array

Learn to calculate the range (max minus min) of a Java array in a single pass, with code, memory diagrams, and real-world uses.

Beginner 📅 Jul 12, 2026 👁 64 views

Find Second Smallest Element in an Array in Java

Learn to find the second smallest element in a Java array in one pass without sorting, including duplicate handling and edge cases.

Beginner 📅 Jul 12, 2026 👁 61 views

Find Second Largest Element in an Array in Java

Learn how to find the second largest element in a Java array in a single pass without sorting, with edge cases and interview tips.

Beginner 📅 Jul 11, 2026 👁 98 views

Find Minimum Element in an Array in Java

Learn to find the minimum element in a Java array with loops, streams, and Collections, including memory diagrams and common mistakes.

Beginner 📅 Jul 11, 2026 👁 119 views

Find Maximum Element in Array in Java

Learn how to find the maximum element in a Java array using loops, Arrays.sort(), Collections, and streams, with full explanations.

Beginner 📅 Jul 11, 2026 👁 83 views

Find Average of Array Elements in Java

Learn to calculate the average of array elements in Java, why type casting to double matters, and how to avoid the integer division trap.

Beginner 📅 Jul 11, 2026 👁 105 views

How to Take Array Input From User in Java

Learn how to accept dynamic array input from users in Java with Scanner, including size validation, loops, and common pitfalls to avoid.

View all 123 Code Snippets articles on one page →