So I've had some classes in Java and I'm working on some of my own code. While playing around with ArrayLists I can't help feeling like I'm doing something wrong. It seems there should be a way to condense the following code to be more efficient. Initially all of the ArrayLists will be empty, but then my code will pull players from a list in a simple .txt file using a scanner object.
Java Code:
ArrayList <String> centers = new ArrayList <String>();
ArrayList <String> forwards = new ArrayList <String>();
ArrayList <String> goalies = new ArrayList <String>();
ArrayList <String> right wings = new ArrayList <String>();
ArrayList <String> left wings = new ArrayList <String>();
ArrayList <String> coaches = new ArrayList <String>();
ArrayList <String> emptyset = new ArrayList <String>();
Is it possible to declare the ArrayLists in a single statement as can be done with int objects? For example,
Java Code:
int x, y, z = 0;
No comments:
Post a Comment