I am looking for a Java class that allows me to store two variables of the type that are joining them, but that also allows me to access them in an ascending / descending way or by index.
Searching I found the HashMap class, which fulfills the first thing I look for, but when it comes to accessing the data it contains, I do not use the get (Object key) method, since I do not know the data that this object stores .
Any suggestions?
Context:
I'm doing a little program about bus stops. I was looking for a way to match the line of the stop with the remaining minutes (until the bus reached this), then my code is as follows:
//Crea una nueva parada
EMTParada parada= new EMTParada();
//Establece el nombre de la parada (código no necesario )
parada.setStopName(nomParada);
//Lectura de paradas (datos obtenidos desde un HTML, clase Document)
for(Element a: busLineList.select("li")){
// A la izquierda agrego el número de la linea y a la derecha los minutos restantes
parada.setLinea(Integer.parseInt(a.getElementsByAttribute("title").text()),a.select("span.minutos"+"[0-9]").text());
}
Method setLinea();
private HashMap linea= new HashMap<Integer,String>();
public void setLinea(int num, String string) {
linea.put(num,string);
}