Would it work as in run? Yes.
Would it do what you want it to do? No.
Objects (like a String) needs to be compared with .equals in Java. As pointer out by Nambari.
Is it recursive? Technically yes since it calls itself.
Is it necesary for it to be recursive? No. You know what it should return so you should just return it.
You want to do something like this:
public AssaultTeam getTeam(String teamName){
for(AssaultTeam team : teams){
if(team.getName().equals(teamName)){
return team;
}
}
AssaultTeam newTeam = new AssaultTeam(teamName);
teams.add(newTeam);
return newTeam;
}
EDIT: I think I it will be beneficial to explain how you can use recursion.
Recursion is defined by two things.
- It has a base case where doesn't call itself anymore.
- If it's not a base case it moves towards the base case by implementing a set of rules.
Say you have a 3x3 square filled with numbers
1 2 3
4 5 6
7 8 9
And you want to start at top left corner and you can either move right or down and you want to end at the bottom right corner. If you add the sum total of each number in the squares you stepped on you want to know the maximum possible;
Some pseudo code
int recurse(x,y)
int max = 0;
if can move right
max = recurse(x+1,y)
if can move down
int tmp = recurse(x,y+1)
if tmp greater than max
max = tmp;
return square[x][y] + max;
Just a silly example of where you would use recursion. Hopefully this helped