Hi i have created a list which reads from a text file. how can i view the contennts of the list outside of the method it was created. I have inserted my code below.
//read Customers.txt and save in an object.
List<Customer2> list = new ArrayList<Customer2>();
File file = new File("Customers.txt");
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line = null;
while ((line = in.readLine()) != null) {
String[] record = line.split(",");
Customer2 customer = new Customer2();
customer.setName(record[0]);
customer.setAddress(record[1]);
customer.setCustomerNumber(record[2]);
customer.setEmailAddress(record[3]);
customer.setPassword(record[4]);
list.add(customer);
}
}
//catch exception
catch (Exception e) {
e.printStackTrace();
}
// tell the user how many objects have been added
System.out.println("Customers Added: ");
System.out.print("" + list.size());
System.out.println("");
for example could i get the size of that list from another class or method other than the one it was defined in? sorry if this is really obvious i am just beginning to use this language.
thanks!