---
title: "how to compare two ArrayLists of type ArrayList<String[]>?"  
description: "how to compare two ArrayLists of type ArrayList<String[]>?"  
author: "Royce Roy"  
published: 2015-04-22  
updated: 2015-04-22  
canonical: https://www.mindstick.com/forum/23112/how-to-compare-two-arraylists-of-type-arraylist-string  
category: "java"  
tags: ["java", "array list"]  
reading_time: 2 minutes  

---

# how to compare two ArrayLists of type ArrayList<String[]>?

I am fairly new to the [concept](https://www.mindstick.com/blog/79/routing-concept-in-dot-net) of [arraylists](https://www.mindstick.com/forum/33734/most-efficient-way-to-simultaneously-sort-three-arraylists-in-java). I have some data in two [arraylist](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp) of type [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)[]. I want to [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) them and [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) them in a new ArrayList<String[]>. following is my code:\

```
ArrayList<String[]> org = arr2;ArrayList<String[]> text = arr3;ArrayList<String[]> outList = new ArrayList<>() ; System.out.println();for(int i = 0; i < org.size(); i++) {    for(int x = 0; x < org.get(i).length; x++) {        System.out.printf("OrgId[%d][%d]: ", i, x);        System.out.println(orgId.get(i)[x]);    }}System.out.println();for(int i = 0; i < text.size(); i++) {    for(int x = 0; x < text.get(i).length; x++) {        System.out.printf("file[%d][%d]: ", i, x);        System.out.println(text.get(i)[x]);    }}
```

\
the [values](https://www.mindstick.com/forum/327/sum-textbox-values) for org and text are as follows: org: {student1,student2,student3} text: {student3,student4,student1,student5} both arraylists are of different sizes. I want to use an [if statement](https://www.mindstick.com/forum/12682/jquery-toggle-if-statement) or some logic that can [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) in the results as: outList: {student1,student3} \
i.e.I want to add only the values which are [present](https://answers.mindstick.com/qa/96635/explain-about-the-various-features-present-in-ms-access) in both the lists, into a new list. Something like this:

## Replies

### Reply by Anonymous User

You could have an outer loop that loops through text and an inner loop that loops through orgId and inside that, compare the two items to see if they are equal.\

```
for( String[] a1 : text ){    for( String[] a2 : objId )    {        if( a1[0].equals(a2[0]) )        {            // do something        }    }}
```


---

Original Source: https://www.mindstick.com/forum/23112/how-to-compare-two-arraylists-of-type-arraylist-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
