You are not quite there yet with your fundamental knowledge so my advice is to continue learning more basics. About your specific question, you should use a datastructure to hold multiple objects of the same kind. There are many data structures that all act differently. If you have done serious work in the months you learned Java then you should have read about arrays. Arrays are data structures but offer the least of functionality and can only be of a fixed size. Lists are probably the next you will get to know. They have variable size and offer a lot more functionality. You also have Sets and Maps, sets don't allow equal objects in it and maps map objects together like a dictionary. These are the most important but you need to know them all in order to pick the right one for the right job.
Now more specific to your question, since you have a player with a position my guess is you have a draw and logic loop somewhere where you would calculate and draw your stuff. Here you can iterate these data structures and perform actions on each of it's contents.
public class Player {
private int x, y, width, height, health;
private Color color;
public Player(int x, int y, int width, int height, int health, Color color) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.health = health;
this.color = color;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getHealth() {
return health;
}
public void draw()
{
//However you draw this player.
}
}
Now you can specify a datastructure to hold <Type Player>, a ArrayList is most probably your best option here. You can add players as you like and do all kind of queries on the list.
List<Player> myPlayerList = new ArrayList<Player>();
myPlayerList.add(new Player(0, 0, 10, 10, 100, Color.GREEN));
myPlayerList.add(new Player(20, 20, 10, 10, 150, Color.RED));
//Call the draw method on all players in the list
for (Player player : myPlayerList)
{
player.draw();
}
//Find a player with certain properties
Player pickedPlayer = null;
for (int i = 0; i < myPlayerList.size(); i++)
{
//Check conditions
if (myPlayerList.get(i).getX() == 0 && myPlayerList.get(i).getY() == 0)
{
//Set picked player to the current iteration
pickedPlayer = myPlayerList.get(i);
//break out of loop
break;
}
}
//You can remove objects from a ArrayList by index or if you know the object
myPlayerList.remove(pickedPlayer);
//If you want to change the list while iterating you need to use a iterator.
for (Iterator<Player> iterator = myPlayerList.iterator(); iterator.hasNext();)
{
Player currentPlayer = iterator.next();
if (currentPlayer.getHealth() <= 0) iterator.remove();
}
Try to find a good use for each type of data structure and understand how each one works.