Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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 PairDemo
{
   public static void main(String[] args)
   {
      String[] names = { "Tom", "Diana", "Harry" };
      Pair<String, Integer> result = firstContaining(names, "a");
      System.out.println(result.getFirst());
      System.out.println("Expected: Diana");
      System.out.println(result.getSecond());
      System.out.println("Expected: 1");
      swap();
   }


   public static Pair<String, Integer> firstContaining(
      String[] strings, String sub)
   {
      for (int i = 0; i < strings.length; i++)
      {
         if (strings[i].contains(sub))
         {
            return new Pair<String, Integer>(strings[i], i);
         }
      }
      return new Pair<String, Integer>(null, -1);
   }
}
Comment

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 + ")"; }
}
Comment

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);
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript get string value of enum 
Typescript :: missing return type on function @typescript-eslint/explicit-function-return-type 
Typescript :: nextjs waiting for compiling problem 
Typescript :: android java loop through all objects in layout 
Typescript :: angular JSON.parse (<anonymous) 
Typescript :: array of linked lists in cpp 
Typescript :: Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement, HTMLDivElement 
Typescript :: hardness of water is due to the presence of salts of 
Typescript :: how to use the pokeapi with javascript 
Typescript :: facts about cleopatra 
Typescript :: integrationtest typescript 
Typescript :: all objects created from a class will occupy equal number? 
Typescript :: after effects how to parent only one property 
Typescript :: netsuite suitescript to upload and rename a file 
Typescript :: typescript interface array of dictionaries 
Typescript :: import path cannot end with ts 
Typescript :: paste elements of a vector r 
Typescript :: how to check if a field exists in a dictionry or not 
Typescript :: nest js decorator 
Typescript :: let variable name : any = () = { return new typescript fie} 
Typescript :: vim remove surrounding brackets with surround plugin 
Typescript :: mixins with parameters typescript 
Typescript :: axios append array to params 
Typescript :: find most similar words from a list python 
Typescript :: Return first k terms from vector 
Typescript :: group list into sublists python 
Typescript :: Laravel 8 working with subdomain routing but its not working 
Typescript :: yup validation typescript 
Typescript :: typescript new instance of interface 
Typescript :: .setRowHeights google script 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =