How would it be possible to return the values in the arraylist onto the screen e.g. System.out.println
I was thinking of a for loop e.g.
for (String s : list)
{
System.out.println(s);
}
But it complains it can’t convert an object to string – how can I convert it to string?
Code:
public static void GetStatsProc(String operation)
{
try {
Process p=Runtime.getRuntime().exec(operation);
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
// Add all lines into an array
ArrayList list = new ArrayList();
list.add(line);
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
}
If your issue is with printing in the for loop, then your list should be declared
and the for loop needs to look like