Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Completely new to java, trying to figure out how to implement this code properly (https://www.askmehelpdesk.com/showthread.php?t=831851)

  • Apr 21, 2017, 04:52 PM
    siccoblue
    Completely new to java, trying to figure out how to implement this code properly
    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


    Code:

            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


    Code:

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

    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

  • All times are GMT -7. The time now is 09:44 PM.