import java.util.ArrayList;

public class Delimiters {
     //  part1   private instances variables          global variables 
	private String openDel;
	private String closeDel;
	
	 //   part2    constructors     
	public Delimiters(String open, String close)
	{
		openDel=open;    
		closeDel=close;
	}
		 
	 //   part3    non-constructor methods     normal methods 
	public ArrayList<String> getDelimitersList(String[] tokens){
		//     ArrayList<DataType> ListName = new ArrayList<DataType>();
		         ArrayList<String> delimiters = new ArrayList<String>();  		         
		           for(int i=0; i<tokens.length; i++){
		        	     if(tokens[i].equals(openDel) || tokens[i].equals(closeDel)){
		        	    	  delimiters.add(tokens[i]);
		        	     }
		           }
		    return delimiters;       
	}
	
	public boolean isBalanced(ArrayList<String> delimiters){
		int countOpen=0;
		int countClose=0; 
		for (int i=0; i<delimiters.size(); i++){ 
			if (delimiters.get(i).equals(openDel)){
			   countOpen++;
			}
			else {
			   countClose++;
			} 			
			if(countClose > countOpen)
				return false;
		}
        return countOpen == countClose;
    }
}

Notes on Difference for Looping through Array, ArrayLists, String

String str for(int i=0; i<str.length(); i++) str.substring(i,i+1) // means get every character in String 01234 "Linda".substring(0,1) "Linda".substring(4) .substring(start , end) [start, end) from start to end-1

Array arr for(int i=0; i<arr.length; i++) arr[i] // means get every element in the arr

ArrayList list for(int i=0; i<list.size(); i++) list.get(i) // means get every item in the ArrayList