Free Puzzle Questions with Answer using Java, C#, JavaScript and PHP

Java Quiz - Check If String Is Valid or Not

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package checkifstringisvalidornot;

/**
 *
 * @author Bereket-Excellerent
 */
public class CheckIfStringIsValidOrNot {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        String input = "]";
        
        boolean result = isValid(input);
        
        System.out.println(result);
    }
    
    public static boolean isValid(String given){
        if(given.equals("")){
            return true;
        }
        else if((given.length()%2) != 0){
            return false;
        }
        else{
            String[] opennings = new String[given.length()/2];
            
            String firstChar = given.substring(0, 1);
            String current = "";
            
            int counter = 0;
            if(firstChar.equals("(") || firstChar.equals("{") || firstChar.equals("[")){
                for(int i=0; i<given.length(); i++){
                    current = given.substring(i, i+1);
                    
                    if(current.equals("(") || current.equals("{") || current.equals("[")){
                        if(counter >= opennings.length){
                            return false;
                        }
                        else{
                            opennings[counter] = current;
                            counter++;
                        }
                    }
                    else{
                        if(current.equals(")")){
                            if(opennings[counter-1].equals("(")){
                                opennings[counter-1] = "";
                                counter--;
                            }
                            else{
                                return false;
                            }
                        }
                        else if(current.equals("]")){
                            if(opennings[counter-1].equals("[")){
                                opennings[counter-1] = "";
                                counter--;
                            }
                            else{
                                return false;
                            }
                        }
                        else if(current.equals("}")){
                            if(opennings[counter-1].equals("{")){
                                opennings[counter-1] = "";
                                counter--;
                            }
                            else{
                                return false;
                            }
                        }
                    }
                }
            }
            else{
                return false;
            }
            
            if(counter == 0){
                return true;
            }
            else{
                return false;
            }
        }
    }
    
}