Frequently Asked Java Program 16: How To Check The Equality Of Two Arrays
Вставка
- Опубліковано 23 січ 2025
- Topic : How To Check The Equality Of Two Arrays
#########################
Udemy Courses:
#########################
Manual Testing+Agile with Jira Tool
************************************
► shorturl.at/xNXZ4
Selenium with Java+Cucumber
********************************
► shorturl.at/aIKMW
Selenium with Python & PyTest
********************************
► shorturl.at/ELW09
Selenium with python using Robot framework
****************************************
► shorturl.at/bcDPZ
API Testing(Postman, RestAssured & SoapUI)
*****************************************
► shorturl.at/uAWY7
Web & API Automation using Cypress with Javascript
********************************************
► rb.gy/4uum2n
Playwright with Javascript
**************************
► shorturl.at/gALZ1
Jmeter-Performance Testing
************************
► rb.gy/ocj7r2
SDET Essencials(Full Stack QA)
*************************
► rb.gy/hlnf2v
Appium-Mobile Automation Testing
************************************
► rb.gy/wmzv64
Java Collections
*****************
► bit.ly/3S66ezE
Python Programming
*********************
► urlis.net/gdsf...
Cucumber BDD Framework
***************************
► bit.ly/3F7d69r
Protractor with Javascript
***************************
► urlis.net/4udd...
####################################
UA-cam Playlists:
####################################
Manual Testing & Agile
***********************
► bit.ly/3ujvaYa
► bit.ly/3OYzxQj
SQL
*************************
► bit.ly/3R6XjeG
► bit.ly/3nE0a1s
► bit.ly/3IeKuuJ
linux & Shell Scripting
**********************
► bit.ly/3up1Z6a
► bit.ly/3nzvGxx
Java
**********************
► bit.ly/3R9QfOs
► bit.ly/3AoRMKM
► bit.ly/3IbTTDn
► bit.ly/3ybXInv
► bit.ly/3yCoHdw
Selenium With Java+Cucumber
********************************
► bit.ly/3P2FMm4
► bit.ly/3yhiIt4
► bit.ly/3uokzet
► bit.ly/3a7XIND
► bit.ly/3umN2S9
► bit.ly/3aar7GW
► bit.ly/3y9kD2S
► bit.ly/3uhLskn
Python
********************************
► bit.ly/3agNgU0
► bit.ly/3NJNnoy
► bit.ly/2CTQ4mR
► bit.ly/3OIYWh1
Selenium With Python,Pytest&Behave
***************************************
► bit.ly/3OHHoC9
► bit.ly/3IeNLdv
► bit.ly/2J4tPeT
► bit.ly/3ydSkAq
Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************
► bit.ly/3nUvlpr
► bit.ly/3nUvE3z
API Testing (Postman,SoapUi,&Rest Assured)
**********************************************
► bit.ly/3OXacWY
► bit.ly/3yh0UhE
► bit.ly/3nC9DWQ
► bit.ly/3yGfhNS
► bit.ly/3OJa11H
► bit.ly/3P2slCC
Mobile App Testing Appium
****************************
► bit.ly/3Al49HG
Performance Testing Jmeter
*******************************
► bit.ly/3nz4fE7
Maven,Jenkins,Git,Github,CI/CD
*******************************
► bit.ly/3P16HPj
► bit.ly/3yhlUVA
► bit.ly/3afYfwT
► bit.ly/3yGzweG
► bit.ly/3yF73Ws
► bit.ly/3NCOmH7
SQL,DB Testing&ETL,Bigdata
*******************************
► bit.ly/3NKOcNY
► bit.ly/3OVpDyI
► bit.ly/3NEvUy0
► bit.ly/3IryxlT
► bit.ly/3RkWBLh
JavaScript Based Automation Tools
********************************
► bit.ly/3nUx51X
► bit.ly/3AqI6Q0
► bit.ly/3yeurbT
► bit.ly/3ujzpTK
Selector Hub Tools
********************
►rb.gy/h3h424
GraphQL
******************
► rb.gy/sj3gys
Cypress API Testing
********************
► shorturl.at/fjKPX
Cypress Web Testing
**********************
► shorturl.at/agjlK
Playwright with Javascipt
**************************
► shorturl.at/adSTY
#PythonArrayEquality
#ArrayComparison
#ArrayEqualityCheck
#PythonArrays
#ArrayMatching
#CompareArrays
#ArrayEqualityProgram
#PythonCoding
#ArrayOperations
#CodeLogic
#PythonProgramming
#CodingChallenge
#ArrayLogic
#ProgrammingPractice
#EqualityCheck
#AlgorithmDesign
#PythonSolutions
#ArrayProblems
#CodingSkills
#PythonSnippets
#ArrayPuzzles
#AlgorithmAnalysis
#ProblemSolving
#ArrayAlgorithms
#PythonCodingTips
#ArrayComparisonLogic
#CodeOptimization
#PythonLearning
#ArrayPatterns
#AlgorithmApproach
#CodingCommunity
#PythonHelp
#ArrayTricks
#ProblemSolvingInPython
#AlgorithmTricks
#CodingInPython
#ArrayManipulation
#PythonTricks
#AlgorithmExplained
#CodeBreakdown
#PythonArrays101
#AlgorithmMastery
#CodingInspiration
#PythonExploration
#ArrayTips
#AlgorithmHacks
#CodingGenius
#PythonCodeSnippets
#ArrayComparisonTricks
#AlgorithmSolutions
The way you are teaching , student from class 5th can also understand👏
Great teaching sir👌👌
Another approach:
int[] arr01 = {2, 3, 5, 7, 11, 13, 17, 19, 23};
int[] arr02 = {7, 3, 5, 2, 11, 13, 17, 19, 23};
if (arr01.length == arr02.length) {
int counter = 0;
for (int element : arr01) {
for (int element2 : arr02) {
if (element == element2) {
counter++;
break;
}
}
}
if (counter == arr01.length) {
System.out.println("The two arrays are equal");
} else {
System.out.println("The two arrays are not equal");
}
} else {
System.out.println("The two arrays are not equal");
}
I like your tutorials. thank you very much!!
You are welcome!
if(a1[i] != a2[i]){
status = false;
break; // very important !!
}
sir, i think this is very easy logic ,,, just once check plzz...
//WAP to check if 2 arrays are equal or not using HashSet:
import java.util.HashSet;
class Check2ArraysEqual1
{
public static void main(String[] args)
{
int[] arr1={1,2,3,4,5};
int[] arr2={1,6,2,4,5};
HashSet hs1=new HashSet();
HashSet hs2=new HashSet();
for(int i=0;i
If one of your array size is not equal the where you put the else statement for that?
thank you
Nice sir..
Thanks
public class HowToCheckArrayisequal {
public static void main(String args[]) {
int a [] = {1,2,3,4,5,6,7};
int a1 [] = {1,2,3,4,5,6,7,5};
boolean flag = true;
if(a.length==a1.length) {
for(int i =0;i
This logic shall work only when last value that is a[4] is not matching we get false, but if a1[0 to 3] not equal to a2[0 to 3] and a1[4]=a2[4] this logic should not work.
Hope this helps.
int[] arr = {1,2,3,4,5};
int[] arr2 = {1,2,7,4,5};
boolean flag = true;
if(arr.length == arr2.length)
{
for(int i = 0; i
No if once if statement will exicuted then it never becomes as true because after if statement there nothing to represent as true so for any index if if is executed once it is not equal if if is not executed then boolean value is remains as true
This logic works. as the if statement only executed if array value is not equal. the only thing i would suggest is we can add break after assigning status = false, when array size increase it would be to get results earlier:
int a1[] = { 1, 2, 3, 4, 6, 6 };
int a2[] = { 1, 4, 3, 4, 5, 6 };
boolean status = true;
if (a1.length == a2.length) {
for (int i = 0; i < a1.length; i++) {
if (a1[i] != a2[i]) {
status = false;
System.out.println("i: "+ i+ " status : "+status);
break;
}
}
} else {
status = false;
}
if (!status)
System.out.println("Arrays are not equal");
else
System.out.println("Arrays are equal");
What are the pros and cons of using each strategy?
sometimes interviewer says that buddy dont use built in methods I want to see your logic building so............
@@atifasadkhan I am literally graduating school now lol
@@jntula so finally you graduated from school nah or still?
Missing break
Commenting for better reach
public static void main(String[] args) {
int a[] = {1,2,3,4,5};
int b[] = {1,2,3,4,5};
int len=a.length;
int count=0;
if(a.length==b.length)
{
for(int i=0;i
🇮🇳🇮🇳🙏🙏👍👍
public static void main(String[] args) {
int[] a1 = { 1, 2, 3, 4 };
int[] a2 = { 1, 1, 1, 4 };
int found = 0;
if (a1.length == a2.length) {
for (int i = 0; i < a1.length; i++) {
int no = a1[i];
System.out.println("====a1["+i+"]="+no);
for (int j = 0; j < a2.length; j++) {
System.out.println("====a2["+j+"]="+a2[j]);
if (no == a2[j]) {
found++;
}
System.out.println("found:"+found);
}
if (found > 1 || found == 0) {
System.out.println("no matching found.11.F:"+found);
break;
}
found = 0;
}
} else {
System.out.println("no match found.22...");
}
Your program is weird, This is easy example :-
int[] arr = {1, 2, 3, 6, 10, 9};
int[] arr2 = {1, 22, 3, 6, 10, 9};
boolean isArrayEqual = true;
for (int i = 0; i < arr.length; i++) {
for (int j = i; j < arr2.length; j++) {
if (arr[i] == arr2[j]) {
break;
} else {
isArrayEqual = false;
}
}
}
if (isArrayEqual) {
System.out.println("EQUAL ARRAY");
} else {
System.out.println("NOT EQUAL ARRAY");
}