Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java array swap

public static void swap(int x, int y, int[] arr) {
  	int temp = arr[x];
  	arr[x] = arr[y];
  	arr[y] = temp;
}
Comment

array.swap java

public static final <T> void swap (T[] a, int i, int j) {
  T t = a[i];
  a[i] = a[j];
  a[j] = t;
}

public static final <T> void swap (List<T> l, int i, int j) {
  Collections.<T>swap(l, i, j);
}

private void test() {
  String [] a = {"Hello", "Goodbye"};
  swap(a, 0, 1);
  System.out.println("a:"+Arrays.toString(a));
  List<String> l = new ArrayList<String>(Arrays.asList(a));
  swap(l, 0, 1);
  System.out.println("l:"+l);
}
Comment

PREVIOUS NEXT
Code Example
Java :: renardfute 
Java :: How to find the Levenshtein distance between two strings of characters, in Java? 
Java :: show confirmation dialog java android 
Java :: java transform hashmap to list 
Java :: android internet permission 
Java :: java socket get ip address of client 
Java :: android studio java random number generator 
Java :: map java get first key 
Java :: throw io exception java 
Java :: java stop program 
Java :: jpa repository delete method return value 
Java :: android elevation not working 
Java :: error: package androidx.multidex does not exist 
Java :: PlatformException (PlatformException(error, Neither user 10024 nor current process has android.permission.WAKE_LOCK., null, java.lang.SecurityException: Neither user 10024 nor current process has android.permission.WAKE_LOCK. 
Java :: check type of variable java 
Java :: java get distinct values from list 
Java :: Unhandled exception: java.lang.InterruptedException 
Java :: onclick android 
Java :: How to efficiently find the index of smallest value that is larger than some target within a sorted array, in Java? 
Java :: java check if divisible 
Java :: how to sort a list of integers in java 
Java :: get file path java 
Java :: array to list 
Java :: return day from date in java 
Java :: jagged array java 
Java :: counting sort java 
Java :: capitalize string java 
Java :: java get input 
Java :: android toast in adapter 
Java :: java array to arraylist 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =