Reputation: 19
Alright so I am working on a small program in which I have a method which accesses an Arraylist.
So:
public void setGroups(int groupA, int groupB, ArrayList< String > groups)
then I have my Arraylist in the body of my main method:
ArrayList groupSets = new ArrayList< String >(
Arrays.asList("group1", "group2" ));
So my question is, how do I call this code in my main method? My issue is with the arraylist part. Also these ints of groupA/B, I will be using these to pull elements out of the ArrayList.
So it would be like?:
playGame(0, 1, ArrayList< String > groupSets);
Except I know that the arraylist part is wrong and I am unsure if the ints are right or wrong as well, they seem right but I could be completely off. Please any help?!
Upvotes: 0
Views: 62
Reputation: 2825
In agreement with both of the partial answers above, let's see if we can make this comprehensive:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GroupStuff {
public static void main(String[] args) {
List<String> groupSets = new ArrayList<>(Arrays.asList("group1", "group2"));
GroupStuff gs = new GroupStuff();
gs.setGroups(0,1,groupSets);
}
public void setGroups(int groupA, int groupB, List<String> groups) {
//Do whatever you do here...
}
}
And....
playGame(0, 1, ArrayList< String > groupSets);
should be
playGame(0, 1, groupSets);
Upvotes: 0
Reputation: 3987
Its just
ArrayList<String> groupSets = new ArrayList<String>();
playGame(0, 1, groupSets);
Upvotes: 0
Reputation: 308753
Your declaration and call are different, so your question is a bit confusing.
The call should not include any type information:
setGroups(groupA, groupB, groups);
Upvotes: 1