Share on Google+Share on Google+

Array Relocation Example

This is a very simple example of Array Relocation. After initialization we later relocate and assign value at any index.


This example demonstrate the Array Relocation where value of any index can be change.


import java.util.Arrays;

public class ArrayReallocation {

  public static void main(String[] args) {

    int[] number1 = new int[] { 1357};
    int[] number2 = Arrays.copyOf(number1, 4);
    int[] number3 = Arrays.copyOfRange(number1, 310);

  private static void showArray(int[] data) {
    StringBuffer stringBuffer = new StringBuffer("[");
    for (int i = 0; i < data.length; i++) {
      if (i < data.length - 1)
        stringBuffer.append(", ");



Posted on: April 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.