Tech/Java

Java Tuple

아다지에토 2014. 8. 20. 14:34

Java에는 튜플이 없다.

그래서 만들어서 써야 한다!

그래서 만들어보자!


===============================================================================================

public class Tuple<X,Y>

{

private X x;

private Y y;

public Tuple(X x, Y y)

{

this.x = x;

this.y = y;

}

public X getX()

{

return x;

}

public Y getY()

{

return y;

}

public void setX(X x)

{

this.x = x;

}

public void setY(Y y)

{

this.y = y;

}

}

===============================================================================================


사용할때는 


Tuple<Integer,Integer> move = new Tuple(4,3);


move.getX();

move.getY();

move.setX(1);

move.setY(3);


와 같이 사용하면 된다.