title: Importing ArrayList from one file to another
body: <p>my question is pretty basic, but I can't seem to find any real help in the questions other people asked...their code is way too complicated.</p>
  
  <p>Basically, I created an ArrayList in one java file, and I'm trying to import it to another java file.  Can I do this?  Or do I just need to rebuild it my 2nd file?</p>
  
  <p>Thanks in advance!</p>
  
  <p>This is the file that created ohnode:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Scanner;
  
  
  public class trimgroup {
  
  
  public static void main(String[] args) throws IOException, StringIndexOutOfBoundsException, NumberFormatException{
  Scanner scan = new Scanner(new File("VspAircraft_calculix_geom.dat"));
  Scanner scan1 = new Scanner(new File("VspAircraft_calculix_geom.dat"));  
  Scanner scan2 = new Scanner(new File("VspAircraft_calculix_geom.dat"));
  FileWriter file = new FileWriter(new File("trimgroup.dat"));
  
  
  
  double ymax=0;
  double ymin1=0;
  double ymin=0;
  double ymineq=0;
  double xmax=0;
  double xmin1=0;
  double xmin=0;
  double xmineq=0;
  double ymaxb=0;
  double ymin1b=0;
  double yminb=0;
  double ymineqb=0;
  double xmaxb=0;
  double xmin1b=0;
  double xminb=0;
  double xmineqb=0;
  
  
  ArrayList&lt;Double&gt; a = new ArrayList&lt;Double&gt;(); //y values of all the nodes
  ArrayList&lt;Double&gt; b = new ArrayList&lt;Double&gt;(); //x values of all the nodes
  ArrayList&lt;Integer&gt; node = new ArrayList&lt;Integer&gt;(); //all the nodes on the wing
  ArrayList&lt;Integer&gt; nodeb = new ArrayList&lt;Integer&gt;();
  ArrayList&lt;Integer&gt; ohnode = new ArrayList&lt;Integer&gt;();
  
  
  
  //Front Spar
  while(scan.hasNextLine()){
   String line = scan.nextLine();
   String [] token = line.split("[,|\\r?\\n]");
  
   if (token.length==2){
  
       for(int i=0;i&lt;token[1].length()-11;i++) {
  
          if (token[1].substring(i,i+12).equals(" NSET=Nspar1")){
          line=scan.nextLine();      // first skip any input that matches the delimiter pattern, and then attempt to return the next token
  
              while(scan.hasNextLine()){
  
              String [] token2= line.split("[,|\\r?\\n]");
  
                  if (token2[0].equals("")){
                      break;
                  }else{
                      String [] token3= line.split("[,|\\r?\\n]");
                      double token2d=Double.parseDouble(token3[2]);
                      double token1d=Double.parseDouble(token3[1]);
                      int token0d=Integer.parseInt(token3[0]);
                      a.add(token2d);
                      node.add(token0d);
                      //Find the max/min
                          if (token2d&gt;ymax){
                              ymax=Double.parseDouble(token3[2]);
  
                          }else{
                          ymin1=Double.parseDouble(token3[2]);}
  
                          if (1/ymin1&gt;ymineq){
                              ymin=token2d;
                              ymineq=1/token2d;}
  
                          if (token1d&gt;xmax){
                              xmax=Double.parseDouble(token3[1]);
  
                          }else{
                              xmin1=Double.parseDouble(token3[1]);}
  
                          if (1/xmin1&gt;xmineq){
                              xmin=token1d;
                              xmineq=1/token1d;}
  
                              line=scan.nextLine();               
                  }
              } 
          }    
      }
    }
  }
  //Back Spar
  while(scan1.hasNextLine()){
   String line = scan1.nextLine();
   String [] token = line.split("[,|\\r?\\n]");
    if (token.length==2){
  
       for(int i=0;i&lt;token[1].length()-11;i++) {
  
          if (token[1].substring(i,i+12).equals(" NSET=Nspar2")){
          line=scan1.nextLine();       
  
              while(scan1.hasNextLine()){
  
              String [] token2= line.split("[,|\\r?\\n]");
  
                  if (token2[0].equals("")){
                      break;
                  }else{
                      String [] token3= line.split("[,|\\r?\\n]");
                      double token2d=Double.parseDouble(token3[2]);
                      double token1d=Double.parseDouble(token3[1]);
                      int token0d=Integer.parseInt(token3[0]);
                      a.add(token2d);
                      node.add(token0d);
                          if (token2d&gt;ymaxb){
                              ymaxb=Double.parseDouble(token3[2]);
  
                          }else{
                          ymin1b=Double.parseDouble(token3[2]);}
  
                          if (1/ymin1b&gt;ymineqb){
                              yminb=token2d;
                              ymineqb=1/token2d;}
  
                          if (token1d&gt;xmaxb){
                              xmaxb=Double.parseDouble(token3[1]);
  
                          }else{
                              xmin1b=Double.parseDouble(token3[1]);}
  
                          if (1/xmin1b&gt;xmineqb){
                              xminb=token1d;
                              xmineqb=1/token1d;}
  
                              line=scan1.nextLine();               
                  }
              } 
          }    
      }
    }
  }
  
  while(scan2.hasNextLine()){
   String line2 = scan2.nextLine();
   String [] token2 = line2.split("[,|\\r?\\n]");
  
   if (token2.length==2){
  
    if (token2[1].equals(" NSET=Nupperskin")){
      line2=scan2.nextLine();
      while (scan2.hasNextLine()){
      String [] token2b = line2.split("[,|\\r?\\n]");
      if (token2b[0].equals("")){
       break;
      }else{
          String [] token3b = line2.split("[,|\\r?\\n]");
          int token2bi=Integer.parseInt(token3b[0]);
          double token2by=Double.parseDouble(token3b[2]);
          double token2bx=Double.parseDouble(token3b[1]);
          if (token2bx&lt;(xmax-xmin)/(ymax-ymin)*token2by+xmin){
              ohnode.add(token2bi);
          }
          if (token2bx&gt;(xmaxb-xminb)/(ymaxb-yminb)*token2by+xminb){
              ohnode.add(token2bi);
          }
  
       line2=scan2.nextLine();
       }
      }
     }
   }
   if (token2.length==2){
  
    if (token2[1].equals(" NSET=Nlowerskin")){
      line2=scan2.nextLine();
      while (scan2.hasNextLine()){
      String [] token2b = line2.split("[,|\\r?\\n]");
      if (token2b[0].equals("")){
       break;
      }else{
          String [] token3b = line2.split("[,|\\r?\\n]");
          int token2bi=Integer.parseInt(token3b[0]);
          double token2by=Double.parseDouble(token3b[2]);
          double token2bx=Double.parseDouble(token3b[1]);
          if (token2bx&lt;(xmax-xmin)/(ymax-ymin)*token2by+xmin){
              ohnode.add(token2bi);
          }
          if (token2bx&gt;(xmaxb-xminb)/(ymaxb-yminb)*token2by+xminb){
              ohnode.add(token2bi);
          }
  
       line2=scan2.nextLine();
       }
      }
     }
   }     
  }
  
  System.out.println(nodeb.size());  
  System.out.println(node.size());
  System.out.println(ohnode.size());
   for (int u=0;u&lt;ohnode.size();u++)
    file.write(ohnode.get(u)+"\r\n");
  
  
  file.close();   
  
  }}
  </code></pre>
  
  <p>This is the text file I'm trying to use the Arraylist ohnode in:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Scanner;
  import java.util.List;
  
  
  public class TrimBox {
  public static void main(String[] args) throws IOException, StringIndexOutOfBoundsException, NumberFormatException{
      Scanner scan = new Scanner(new File("VspAircraft_calculix_geom.dat"));
      Scanner scan2 = new Scanner(new File("trimgroup.dat"));  
      FileWriter file = new FileWriter(new File("trimbox_nodes.dat"));
  
      ArrayList&lt;Integer&gt; node = new ArrayList&lt;Integer&gt;(); 
  //ALL the nodes of the entire wing
  
      while (scan.hasNextLine()){
          String line = scan.nextLine();
          String [] token= line.split(",|\\r?\\n]");
  
          if (token.length==2){
              for(int i=0;i&lt;token[1].length()-11;i++) {
                  if (token[1].substring(i,i+12).equals(" NSET=Nspar0")){
                      //Ask user to change the number after Nspar in modelcenter to denote which spar to apply load
  
                      line=scan.nextLine();
                      while(scan.hasNextLine()){
                          String [] token2= line.split("[,|\\r?\\n]");
                          if (token2[0].equals("")){
                              break;
                          }else{
                              String [] token3= line.split("[,|\\r?\\n]");
                              //System.out.println(token3[2]);
                              int token0d=Integer.parseInt(token3[0]);
                              node.add(token0d); //Add the node tokens to array node
  
                              //Order of the tokens from VSPAircraft_calculix_geom.data
                              //node, x value, y value, z value
                   }
               }
           }
       }
   }
  
  }
  }
  }
  /** We want to import the arraylist from trimgroup.dat (nodeb or ohnode?)
   * Can we also import arraylist node from trimgroup.dat?
   * -If nodes from VSP==nodeb (/ohnode?), skip, if not, add token to new array
   * -Write it to a new file
   * 
   * Probably can use some function of java.util.ArrayList to see if ArrayLists are equal
   * 
   * Why do we have ArrayLists instead of Arrays?  
   */
  </code></pre>