You're trying to assign the return value of clients.get(clients.size())
to the string hey
, but the object returned is a ClientThread
, not a string. As Andre mentioned, you need to use the proper index as well.
As far as your second error is concerned, there is no static method remove()
on the type ClientThread
. Really, you likely wanted the remove method of your List
instance, clients
.
You can remove the last item from the list, if there is one, as follows. Since remove also returns the object that was removed, you can capture the return and use it to print out the name:
int size = clients.size();
if (size > 0) {
ClientThread client = clients.remove(size - 1);
System.out.println(client + " has logged out.");
System.out.println("CONNECTED PLAYERS: " + clients.size());
}