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 :: why are my if statements not working with inputs in java 
Java :: how to initialize main in java 
Java :: org.springframework.security.oauth2.jwt.JwtEncoder 
Java :: java session timeout 
Java :: how to add data into list model in android 
Java :: Java Program to Change the Border of a JFrame: 
Java :: how to recognize a pressed key in java 
Java :: date java use fix timezone 
Java :: android list tostring 
Java :: java program to convert milliseconds to minutes and seconds 
Java :: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
Java :: byte array in java 
Java :: java clear scanner2 
Java :: Create EntityManager Hibernate 
Java :: Java if...else 
Java :: java infinite for loop 
Java :: how to change background color of grid in grid layout in android 
Java :: is c# similar to java 
Java :: 1 elemenet array java 
Java :: java user home directory macos 
Java :: what is abstraction in java 
Java :: Java Remove Elements from HashSet 
Java :: java linked list swap elements 
Java :: java to c# converter 
Java :: The Longest Substring 
Java :: how to set the length to int array in java 
Java :: java design patterns 
Java :: convert character arraylist to array 
Java :: method overloading 
Java :: super 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =