- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the intersection of two arrays in java?
To find the intersection of two arrays in java use two loops. The outer loop is to iterate the elements of the first array whereas, the second loop is to iterate the elements of the second array. Within the second loop compare the elements of the two arrays:
Example
public class IntersectionOfTwoArrays { public static void main(String args[]) { int myArray1[] = {23, 36, 96, 78, 55}; int myArray2[] = {78, 45, 19, 73, 55}; System.out.println("Intersection of the two arrays ::"); for(int i = 0; i<myArray1.length; i++ ) { for(int j = 0; j<myArray2.length; j++) { if(myArray1[i]==myArray2[j]) { System.out.println(myArray2[j]); } } } } }
Output
Intersection of the two arrays :: 78 55
- Related Articles
- Intersection of two arrays in Java
- How to find intersection between two Numpy arrays?
- How to get the intersection of two arrays in MongoDB?
- Intersection of two arrays in C#
- Intersection of Two Arrays in C++
- Intersection of two arrays JavaScript
- Find Union and Intersection of two unsorted arrays in C++
- C++ program to find union and intersection of two unsorted arrays
- Intersection of Two Arrays II in Python
- How to Find the Union of Two Arrays in Java?
- How to Create an Array using Intersection of two Arrays in JavaScript?
- Find the Intersection Point of Two Linked Lists in Java
- C program to perform intersection operation on two arrays
- The intersection of two arrays in Python (Lambda expression and filter function )
- Get the intersection of two sets in Java

Advertisements