Log in

View Full Version : Completely new to java, trying to figure out how to implement this code properly


siccoblue
Apr 21, 2017, 04:52 PM
I'm trying to implement something at the moment and am having issues doing so properly


So what I'm trying to do here is add this



public static Player getPlayer(String name) {
for (int i = 0; i < Config.MAX_PLAYERS; i++)
{
if (players[i] != null && players[i].playerName.equalsIgnoreCase(name))
{
return players[i];
}
}


Into this



public static Player getPlayer(String name) {
return Arrays.stream(players).filter(p -> p != null && p.playerName.equalsIgnoreCase(name)).findFirst().g et();

}


I've tried just flat out replacing it but eclipse doesn't like that and tells me I need to return the type of player, but I have no idea what that means, how can I implement these together without breaking my code?

I hate to ask for spoonfeeding me but could someone also explain the process here for making it work properly? I'm trying my best to kind of learn as I go