Java ArrayList string split with file handling

I’m trying to split the elements of ArrayList using space (” “) and here’s the code:

String gg = testarray.toString().replace(",","").replace("[","").replace("]","");
             String key [] = gg.split(" ");
             String gg1 = key[i].trim();

But when I print the results nothing changes. I want to split this example
t2=1; when I use the split it doesn’t display the t2=1; it will only work If I put spaces between them.

Input:
{

int a[3],t1,t2;

t1= 2; a[0]= 1; a[1]= 2; a[t1]= 3;

t2= -(a[2] + t1 * 6) / (a[2] – t1);

if t2 > 5
then

print ( t2 );

else {

int t3 ; t3 = 99 ; t2 = -25 ;

print(- t1 +t2 * t3);

} endif

}

Output:
Keywords:int if then else int
Operators:+ * / – *
Symbols:{ ( { ; ; ; } }
Constants:5 99 -25

Entire code:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class Compiler {

    /**
     * @param args the command line arguments
     */

    @SuppressWarnings("empty-statement")
    public static void main(String[] args) {
        // TODO code application logic here

        String fileName = "input.txt";

        // This will reference one line at a time
        String line = null;

        ArrayList < String > keywords = new ArrayList < > (Arrays.asList("auto", "case", "char", "const", "continue", "default",
            "do", "double", "else", "break", "enum", "extern", "float", "for", "goto",
            "if", "int", "long", "register", "return", "short", "signed",
            "sizeof", "static", "struct", "switch", "typedef", "union",
            "unsigned", "void", "volatile", "while", "then", "int"));

        HashSet < String > ops = new HashSet < String > ();
        ops.add("+");
        ops.add("-");
        ops.add("/");
        ops.add("*");

        HashSet < String > symbols = new HashSet < String > ();
        symbols.add(";");
        symbols.add("}");
        symbols.add(",");
        symbols.add("{");
        symbols.add(")");
        symbols.add("(");
        HashSet < String > posconstants = new HashSet < String > ();
        HashSet < String > negconstants = new HashSet < String > ();
        for (int i = 0; i <= 100; i++) {
            int number = (i);
            String posstring = Integer.toString(number);
            posconstants.add(posstring);
        }
        for (int i = -100; i <= -1; i++) {
            int number = (i);
            String negstring = Integer.toString(number);
            negconstants.add(negstring);
        }
        try {
            String test[];
            // FileReader reads text files in the default encoding.
            FileReader fileReader =
                new FileReader(fileName);
            // Always wrap FileReader in BufferedReader.
            BufferedReader bufferedReader =
                new BufferedReader(fileReader);
            //ArrayList<String> newarray = new ArrayList<String>();
            List < String > testarray = new ArrayList < String > ();;
            while ((line = bufferedReader.readLine()) != null) {
                test = line.split("\s+");
                testarray.addAll(Arrays.asList(test));
            }
            System.out.print("Keywords:");
            for (int i = 0; i < testarray.size(); i++) {
                String gg = testarray.toString().replace(",", "").replace("[", "").replace("]", "");
                String key[] = gg.split(" ");
                String gg1 = key[i];
                if (keywords.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
            }
            System.out.print("n");
            System.out.print("Operators:");
            for (int i = 0; i < testarray.size(); i++) {
                String gg = testarray.toString().replace(",", "").replace("[", "").replace("]", "");
                String key[] = gg.split(" ");
                String gg1 = key[i].trim();
                if (ops.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
            }
            System.out.print("n");
            System.out.print("Symbols:");
            for (int i = 0; i < testarray.size(); i++) {
                String gg = testarray.toString().replace(",", "").replace("[", "").replace("]", "");
                String[] key = gg.split(" ");

                String gg1 = key[i].trim();

                if (symbols.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
            }
            System.out.print("n");
            System.out.print("Constants:");
            for (int i = 0; i < testarray.size(); i++) {
                String gg = testarray.toString().replace(",", "").replace("[", "").replace("]", "");
                String key[] = gg.split(" ");
                String gg1 = key[i].trim();
                if (posconstants.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
                if (negconstants.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
            }
            for (int i = 0; i < testarray.size(); i++) {
                String gg = testarray.toString().replace(",", "").replace("[", "").replace("]", "");
                String key[] = gg.split("|");
                String gg1 = key[i].trim();
                if (!posconstants.contains(gg1)) {
                    System.out.print(gg1 + " ");
                }
            }
            // Always close files.
            bufferedReader.close();
        } catch (FileNotFoundException ex) {
            System.out.println(
                "Unable to open file '" +
                fileName + "'");
        } catch (IOException ex) {
            System.out.println("Error reading file '" + fileName + "'");
        }
    }
}