There are two ways to do this:

  1. A for loop
  2. Using the iterator method.

for loop:

for(x currentX : GetList()) {
    // Do something with the value
}

This is what's called a "for-each" loop, and it's probably the most common/preferred method of doing this. The syntax is:

for(ObjectType variableName : InCollection)

You could also use a standard for loop:

ArrayList<x> list = GetList();
for(int i=0; i<list.size(); i++) {
     x currentX = list.get(i);
     // Do something with the value
 }

The syntax for this is:

for(someStartingValue; doSomethingWithStartingValue; conditionToStopLooping)

iterator method:

Iterator<x> iterator = GetList().iterator();
while(iterator.hasNext()) {
    x currentX = iterator.next();
    // Do something with the value
}
Answer from Caleb Brinkman on Stack Overflow
🌐
Blogger
javarevisited.blogspot.com › 2012 › 03 › how-to-loop-arraylist-in-java-code.html
5 Ways to Loop or Iterate over ArrayList in Java?
We can iterate on Java ArrayList using foreach loop introduced in Java 5, by far most clean method until you don't need to remove elements from ArrayList in that case you must use Java Iterator for looping or iterating over ArrayList.
🌐
Tabnine
tabnine.com › home page › code › java › java.util.arraylist
java.util.ArrayList.iterator java code examples | Tabnine
public Iterator makeEmptyIterator() { ArrayList list = new ArrayList(); return new IteratorChain(list.iterator()); } origin: AltBeacon/android-beacon-library ·
Find elsewhere
🌐
Android Developers
developer.android.com › api reference › arraylist
ArrayList | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Stack Overflow
stackoverflow.com › questions › 19159403 › how-do-i-implement-a-nested-arraylist-and-iterate-through-them-in-android-java
How do I implement a nested ArrayList and iterate through them in Android Java - Stack Overflow
It's not clear from your question, but if you're trying to decide whether a given Byte segment is in one of the arrays and don't care about iterating over them, it would be cleaner and more efficient to use a Set<Byte> instead of ArrayList<Byte>. Set provides a fast contains() method for this purpose.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-loop-arraylist-in-java
How to loop ArrayList in Java
One of the easiest way to iterate through an ArrayList is by using for loop:
🌐
Crunchify
crunchify.com › java j2ee tutorials › how to iterate through java list? seven (7) ways to iterate through loop in java
How to iterate through Java List? Seven (7) ways to Iterate Through Loop in Java • Crunchify
December 28, 2025 - For Loop: 0.014s For Loop Object: 0.218s While Iterator: 0.021s While Loop: 0.01s Stream ForEach: 0.361s ... Instant start = Instant.now(); Instant end = Instant.now(); // create list List crunchifyList = new ArrayList(); for(Long i=0L; i For Loop Example.”); start = Instant.now(); for(int i=0;i Advance For Loop Example..”); start = Instant.now(); for(String temp:crunchifyList){ //System.out.println(temp); } end = Instant.now(); long t2 = Duration.between(start, end).getNano();
Top answer
1 of 5
1

Use, Set Collection Class,

Set<String> set  = new HashSet<String>(Array);
resim_list.addAll(set);

Now here Set will remove all duplicates values from your ArrayList.

2 of 5
0
    public static ArrayList<String> Array = new ArrayList<String>();

    public static ArrayList<String> resim_list=new ArrayList<String>();

In your activity

    Array = bundle.getStringArrayList("string-array");
   // already Array is initalized. no need to initialize again
    GridViewConfig.addImageUrls();// call the add method

GridViewConfig class

    public static class GridViewConfig {
    public static ArrayList<String> resim_list=new ArrayList<String>();

    public static ArrayList<String> getResim_list() {
        return resim_list;
    }

    public void setResim_list(ArrayList<String> resim_list) {
        GridViewConfig.resim_list = resim_list;
    }

    public static void addImageUrls() {
        Set<String> hs = new LinkedHashSet<String>(Array);// set of unique elments 
        // LinkedHashSet maintains insertion order 
        resim_list.addAll(hs);
        for(int i=0;i<resim_list.size();i++)
        {
          System.out.println("NEW RESIM_LIST" + resim_list.get(i));

        }
    }
}

Edit:

Declare this before onCreate()

public  ArrayList<String> Array = new ArrayList<String>();
public  ArrayList<String> resim_list=new ArrayList<String>();

In your onCreate()

Array = bundle.getStringArrayList("string-array");
addImageUrls();

Then define addImageUrls in your activity class as below

      public  void addImageUrls() {
        ArrayList<String> resim_list=new ArrayList<String>();
        Set<String> hs = new LinkedHashSet<String>(Array);// set of unique elments 
        // LinkedHashSet maintains insertion order 
        resim_list.addAll(hs);
        for(int i=0;i<resim_list.size();i++)
        {
          System.out.println("NEW RESIM_LIST" + resim_list.get(i));
        }   
      }  

Array is declared with a class scope. No need to use static modifies. If you intend to use it in another class pass it using intent.

🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java arraylist foreach()
Java ArrayList forEach() with Examples - HowToDoInJava
January 12, 2023 - List<String> list = Arrays.asList("A","B","C","D"); list.forEach(System.out::println); A Consumer implementation takes a single argument, and returns no value. We can also pass the custom actions we have created in other places.
🌐
Javatpoint
javatpoint.com › java-arraylist-iterator-method
Java ArrayList Iterator() method with Examples - Javatpoint
Java ArrayList Iterator() method with Examples on add(), addAll(), clear(), clone(), contains(), ensureCapacity(), get(), indexOf(), isEmpty(), iterator(), lastIndexOf(), listIterator(), remove(), removeAll(), subList(), toArray(), trimToSize() etc.