Java Array Swap swap(byte[] bytes)

Here you can find the source of swap(byte[] bytes)

Description

swap

License

Open Source License

Declaration

private static void swap(byte[] bytes) 

Method Source Code

//package com.java2s;

public class Main {
    private static void swap(byte[] bytes) {
        int half = bytes.length / 2;
        for (int i = 0; i < half; i++) {
            byte temp = bytes[i];
            bytes[i] = bytes[half + i];//from w  w w . ja va2 s  .  c om
            bytes[half + i] = temp;
        }
    }

    public static String swap(String str) {
        char[] chars = str.toCharArray();
        int half = chars.length / 2;
        for (int i = 0; i < half; i++) {
            char temp = chars[i];
            chars[i] = chars[half + i];
            chars[half + i] = temp;
        }
        return new String(chars);
    }
}

Related

  1. swap(boolean[] array, int i1, int i2)
  2. swap(byte size, byte[] target, short targetOffset, byte[] a, short aOffset)
  3. swap(byte[] b1)
  4. swap(byte[] buffer, int i, int j)
  5. swap(byte[] data)
  6. swap(byte[] data, int p, int q)
  7. swap(byte[] rv, int offsetA, int offsetB)
  8. swap(Comparable[] a, int oldIndex, int newIndex)