In Java, I'm trying to store a User object in an ArrayList and before storing / adding it - I'm asking the index number where this object should be stored in. When he enters the Index Number, I want to check if that Index is empty i.e no other User object is stored on that index - if it's empty, the new User will be added and if it's already occupied, I'll ask the user to enter a valid Index number again..
So the question is - how do I check if a specific Index in an ArrayList is empty?
I'm aware that there exists this method ArrayList.contains(Object e) but the issue here is, I want to see if a specific INDEX exists, not if an OBJECT exists.. So kindly let me know how I can achieve that, Thank You.