Hi all, I want to parse the elements in my arraylist to double. May I know how to implement that?
import java.io.*;
import java.util.*;
public class Array2
{
static ArrayList myDouble = new ArrayList();
static String[] temp;
static String[][] finalTemp;
static String[] arr;
static int rows;
public static void main(String args[])
{
try
{
BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\Testing2.txt")); //reading files in specified directory
String str = null;
while ((str = in.readLine()) != null) //file reading
{
str = str.trim();
temp = str.split(",");
myDouble.add(temp);
}
rows = myDouble.size();
finalTemp = new String[rows][];
for (int i=0; i<rows; i++)
{
arr = (String[])myDouble.get(i);
finalTemp[i] = arr;
}
for(int i=0; i<rows; i++)
{
for(int j=0; j<finalTemp[i].length; j++)
{
System.out.print(finalTemp[i][j]);
}
System.out.println("");
}
in.close();
}catch( IOException ioException ) {}
}
}
This is the codes I have so far. It can print out the output I want. However, I realised I need the 2D array finalTemp to be double, and not string. May I know how can I change it?