Reding a file and storing the string as well as numeric value in array in specific format
<p>I have a input file named file.txt with the contents</p>

<pre><code>Zone
Diameter    5
-321    -560    5811
-209    -580    2935
-27     -409    3580
-1075   -220    2847
-1045   206     2827
-19     410     3570
-205    570     2929
-310    565     5768
2.0     3.0     2.0
Zone
Diameter    50
4379    461     23390
484     -264    13447
1259    -516    11969
182     -669    9530
1366    -931    12720
1553    2350    -18702
-3458    6112   -24596
-3606   -6347   -24995
1491    -2267   -18694
1315    835     12740
193     631     9525
12      1252    490     11942
13      520     211     13311
14      4308    -174    23624
</code></pre>

<p>I am looking for an output like:</p>

<pre><code>    zone=1
    x=[1.0 2.0 1.0 2.0 1.0.......2.0 1.0]
    similarly y=[]
    z=[]
    then
    zone=2
    x=[5.0 25.0 15 25 41 25 16 25]
    similarly y=[]
    z=[]
</code></pre>

<p>However, I am getting the values of x=[] for zone=2 from the starting of zone=1, as I am using x.add(scanner.nextDouble()).</p>

<p>Please help me. Thanks in advance.</p>

<pre><code>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boltcal1103;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Neha
 */
public class NewMain {
private static ArrayList&lt;Double&gt; x;
private static ArrayList&lt;Double&gt; y;
private static ArrayList&lt;Double&gt; z;
private static String next1;

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
    // TODO code application logic here
    //File file1 = new File("file.txt");

    Scanner scanner = new Scanner(new FileReader("file1.txt"));
    String line=null,word="Zone",next = null, next1=null;
    int count=1;
    while(scanner.hasNext()) {
        line = scanner.nextLine();
        if (line.equals(word)) {
            if (count &gt; 1) {
                System.out.println(x);
                System.out.println(y);
                System.out.println(z);
            }
            //    int b;
            //  String next1;
            if(scanner.hasNextLine()){
                String nextLine1 = scanner.next();
                System.out.println("name :"+nextLine1);
                //   scanner.useDelimiter("\t");
                if(scanner.hasNext())
                {

                    //   scanner.useDelimiter(" ");
                    next1 = scanner.next();
                    System.out.println("value of diameter:"+next1);
                    //b = Integer.parseInt(scanner.next());
                    //System.out.println("value of diameter:"+b);
                    //      scanner.useDelimiter("\n");
                    scanner.nextLine();
            }}




            System.out.println("zone=:"+count);
            count++;
            x = new ArrayList&lt;Double&gt;();
            y = new ArrayList&lt;Double&gt;();
            z = new ArrayList&lt;Double&gt;();
        }


        else {
            // String delims="";
            String[] d = line.split("\t");
            //         System.out.println("zone=:"+d);

            x.add(Double.parseDouble(d[0]));
            y.add(Double.parseDouble(d[1]));
            z.add(Double.parseDouble(d[2]));
            //      System.out.println("zone=:"+count);
            //  System.out.println(d[0]);
            //  System.out.println(d[1]);
            //  System.out.println(d[2]);
            int i;
            for(i=0;i&lt;x.size();i++)
            {
                Double get1 = x.get(i);
                // System.out.println("value of x:"+get1);
                Double get2 = y.get(i);

                Double get3 = z.get(i);
                double x1 = get1*get1;
                double y1 = get2*get2;
                double z1 = get3*get3;
                System.out.println("x1:"+x1+"\ty1:"+y1+"\tz1:"+z1);


        } }

    }

    if (count &gt; 1) {
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
    }
}
</code></pre>
