Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:53:21+00:00 2026-05-16T10:53:21+00:00

OK, so here is my ArrayList : private List<ClientThread> clients = new ArrayList<ClientThread>(); and

  • 0

OK, so here is my ArrayList:

private List<ClientThread> clients = new ArrayList<ClientThread>();

and here is what I am trying to do:
I am trying to remove the last known item from the ArrayList I posted above. I’m trying to do this with the code below:

    } catch(SocketException re) {


                            String hey = clients.get(clients.size());
                            ClientThread.remove(hey);
                            System.out.println(hey + " has logged out.");
                            System.out.println("CONNECTED PLAYERS: " + clients.size());
}

but I am getting this error:

C:\wamp\www\mystikrpg\Server.java:147: incompatible types
found   : Server.ClientThread
required: java.lang.String
                        String hey = clients.get(clients.size());
                                                ^
C:\wamp\www\mystikrpg\Server.java:148: cannot find symbol
symbol  : method remove(java.lang.String)
location: class Server.ClientThread
                        ClientThread.remove(hey);
                                    ^
2 errors

What am I doing wrong?
It’s supposed to remove the last known item from my ArrayList.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:53:21+00:00Added an answer on May 16, 2026 at 10:53 am

    It should be:

    ClientThread hey = clients.get(clients.size() - 1);
    clients.remove(hey);
    

    Or you can do

    clients.remove(clients.size() - 1);
    

    The minus ones are because size() returns the number of elements, but the ArrayList’s first element’s index is 0 and not 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove an object from an ArrayList and here is the
Here is a simple sorting program of an ArrayList: ArrayList<String> list = new ArrayList<String>();
private List<String> longStr = new java.util.ArrayList<String>(); private List aList = null; private String []
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
I have problem adding arraylist to list view, will explain about my problem here..
I am trying to serialize an ArrayList<Prescription> using an ObjectOutputStream Here is the Prescription
My question is really simple. When should I use List, IEnumerable and ArrayList. Here's
Here is my data model (simplified), public class AddressBook { private List<Group> groups =
i am trying to fetch data from SQLite to list view but my list
Here is some pseudo code as follows. public class MyObject { private List<Object> someStuff;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.