Do it like i have said
List<CoordinatesParamas> lCoordinates = new ArrayList<CoordinatesParamas>();
while(sc.hasNextLine()) {
CoordinatesParamas temp = new CoordinatesParamas();
String pair = sc.nextLine();
String[] s = pair.split(" ");
temp.setLatitude(s[0])
temp.setLongitude(s[1])
lCoordinates.add(temp );
}
and then you can access them like:
for(CoordinatesParamas c : lCoordinates)
System.out.println(c.getLatitude()+" "+c.getLongtitude());
Actually your problem is that you got a variable temp
and in the loop you write all the coordinates to this object, but never store the object with the acutal values. instead you override the object with every iteration.
But if you really want to store all the coordinates in a list of strings. there is no need for the object which holds lat and long then you can easily do:
List<String>coord = new ArrayList<String>();
while(sc.hasNextLine())
{
String pair = sc.nextLine();
String[] s = pair.split("\t");
coord.add(s[0]);
coord.add(s[1]);
}
System.out.println(coord);
and get the same result like printing them in the loop, but now you can use this list coord as often as you want because all coords are added. But pls try to use the object you have created or use a Map<String,String>
which holds a mapping of lat and long.
*note: if you do coord = new ArrayList<String>(Arrays.asList(new String[]{tmp.getLatitude(), tmp.getLongitude()}));
you are creating a new empty arraylist with one pair of lat and long every iteration of your whileloop! if you print them there, it works. but if you print them after the loop, the coord
list will only hold the last lat and long.