if you have problems with the code, you can try this, simple code to store the string and two int values ββin map
class MyCoord{ private int X; private int Y; public MyCoord() { this(0,0); } public MyCoord(int X, int Y) { this.X = X; this.Y = Y; } public int getX() { return X; } public int getY() { return Y; } public void setX(int X) { this.X = X; } public void setY(int Y) { this.Y = Y; } }
// the main class begins
public class PointDemo{ public static void main(String[] args) { Map <String,MyCoord> multiplePoints=new HashMap<String, MyCoord>(); multiplePoints.put("point1", new MyCoord(10, 20)); multiplePoints.put("point2", new MyCoord(100, 2000)); MyCoord coord=multiplePoints.get("point1"); System.out.println(coord.getX() +" : "+coord.getY()); } }
source share