Skip to content

Instantly share code, notes, and snippets.

@rokon12
Created July 12, 2017 11:10
Show Gist options
  • Save rokon12/eabf64afc31389133160eae18089a006 to your computer and use it in GitHub Desktop.
Save rokon12/eabf64afc31389133160eae18089a006 to your computer and use it in GitHub Desktop.
package com.bazlur.ds;
/**
* @author Bazlur Rahman Rokon
* @since 7/12/17.
*/
public class Pair<T, U> {
private final T x;
private final U y;
private Pair(T x, U y) {
this.x = x;
this.y = y;
}
public T getX() {
return x;
}
public U getY() {
return y;
}
public static <T, U> Pair<T, U> of(T x, U y) {
return new Pair<>(x, y);
}
@Override
public String toString() {
return "(" + x + "," + y + ')';
}
}
package com.bazlur.ds;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Bazlur Rahman Rokon
* @since 7/12/17.
*/
public class PairDemo {
public static void main(String[] args) {
Map<Integer, List<Pair<Integer, Integer>>> map = new HashMap<>();
List<Pair<Integer, Integer>> pairs = Arrays.asList(Pair.of(3, 2), Pair.of(3, 4), Pair.of(6, 7));
List<Pair<Integer, Integer>> pairs2 = Arrays.asList(Pair.of(4, 2), Pair.of(1, 4), Pair.of(4, 7));
map.put(1, pairs);
map.put(2, pairs2);
System.out.println(map);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment