modify the main function for arraylist