Skip to content

Instantly share code, notes, and snippets.

@pfalabella
Created December 15, 2012 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfalabella/4293973 to your computer and use it in GitHub Desktop.
Save pfalabella/4293973 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.lang.*;
import static java.lang.System.out;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
List<Pair<?>> lst = new ArrayList<Pair<?>>();
lst.add(new Pair<String>("a","b"));
lst.add(new Pair<Integer>(1,2));
Application.SwapAll(lst);
for(Pair<?> pair: lst) out.println(pair);
}
}
class Pair<T> {
T First, Second;
public Pair(T First, T Second) {
this.First=First;
this.Second=Second;
}
public String toString() {
return String.format("(%s, %s)",First.toString(),Second.toString());
}
}
class Application {
public static <T> void Swap(Pair<T> pair) {
T temp=pair.Second;
pair.Second = pair.First;
pair.First = temp;
}
public static void SwapAll(List<Pair<?>> lst) {
for(Pair<?> pair: lst) Application.Swap(pair);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment