Answers for "java pair swap value"

0

method swap to the Pair class of that swaps the first and second elements value of the pair in generic Pair class in java

public class Pair<T>
    {
       private T first;
       private T second;



   public Pair(T firstElement, T secondElement)
   {
      first = firstElement;
      second = secondElement;
   }


   public T getFirst() { return first; }

   public T getSecond() { return second; }

  public void swap()
  {

   T temp = first;
    first = second;
    second = temp;
  }

   public String toString() { return "(" + first + ", " + second + ")"; }
}
Posted by: Guest on November-23-2020
0

method swap to the Pair class of that swaps the first and second elements value of the pair in generic Pair class in java

public Pair<U,T> swap() {
  return new Pair(second, first);
}
Posted by: Guest on November-23-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language