# Compare two sets of arrays

**URL:** <https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Natural\
**Created:** [January 30, 2023, 6:23am UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666 "2023-01-30T06:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaniv\_Zisano](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/yaniv_zisano/32/17410_2.png) [@Yaniv\_Zisano](https://techcommunity.softwareag.com/u/Yaniv_Zisano)\
**Post date:** [January 30, 2023, 6:23am UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/1 "2023-01-30T06:23:31Z")

</div>

I want to compare 2 sets of array of 16 items to determine if the items are identical both in position and values.

wrong:  
arr1 (1,2,3, **4** ,4,6,7,8,9,10,11,12,13,14,15,16)  
arr2 (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

wrong:  
arr1 ( **2** ,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16)  
arr2 (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

correct:  
arr1 (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)  
arr2 (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

How can I achieve this?

---

<div class="post-metadata">

**Author:** ![Lukas\_Hundemer](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/lukas_hundemer/32/113_2.png) [@Lukas\_Hundemer](https://techcommunity.softwareag.com/u/Lukas_Hundemer)\
**Post date:** [January 30, 2023, 8:47am UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/2 "2023-01-30T08:47:19Z")

</div>

if arr1(1:16) = arr2(1:16)  
Print ‘same’  
else  
Print ‘not same’  
end-if

Do not use “(\*)” on both sides.

Kind regards  
Lukas

---

<div class="post-metadata">

**Author:** ![amnon\_a](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/amnon_a/32/21969_2.png) [@amnon\_a](https://techcommunity.softwareag.com/u/amnon_a)\
**Post date:** [January 30, 2023, 9:21am UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/3 "2023-01-30T09:21:35Z")

</div>

You can redefine both arrays and compare the redefined fields

---

<div class="post-metadata">

**Author:** ![Avik\_Dey1](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@Avik\_Dey1](https://techcommunity.softwareag.com/u/Avik_Dey1)\
**Post date:** [January 31, 2023, 7:41am UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/4 "2023-01-31T07:41:46Z")

</div>

Hi, you can use the equals() method of java.util.Arrays.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [February 16, 2023, 9:46pm UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/5 "2023-02-16T21:46:28Z")

</div>

If you are concerned with performance, redefine the two arrays as follows (I am simply assuming the arrays are alpha and five positions long).

1 arr1 (a5,1:16) would become #all1 (a80)

A similar change would be made for arr2 and #all2.

Now you check to see if #all1 = #all2.

One comparison as opposed to sixteen.

If this is done a few million times a day, you might not have to increase the power of your computer.

Steve Robinson  
(still concerned about performance)

1

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [August 15, 2023, 9:47pm UTC](https://techcommunity.softwareag.com/t/compare-two-sets-of-arrays/268666/6 "2023-08-15T21:47:00Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
