How to compare the equality of an array char elements with the another array of char individually | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to compare the equality of an array char elements with the another array of char individually

16th Oct 2021, 1:42 AM
No Mercy
No Mercy - avatar
2 Answers
+ 1
Simple way: Use a for loop to compare each of the elements individually. Boolean equal=true; for(int i=0;i<arr1.length;++i)//both arrays are of same size-assumption { if(arr1[i]!=arr2[i]) { equal=false; break; } } More efficient way: https://www.tutorialspoint.com/compare-two-char-arrays-in-a-single-line-in-java Use the search bar before asking, because this question looks like already asked question =)
16th Oct 2021, 1:57 AM
Rishi
Rishi - avatar
0
7
19th Oct 2021, 10:33 PM
Flower Beeta
Flower Beeta - avatar