Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static int[] resizeArray(int[] array, int newsize) {
        if (null == array) {
            return null;
        }
        int[] newArr = new int[newsize];
        if (newsize > array.length) {
            System.arraycopy(array, 0, newArr, 0, array.length);
        } else {
            System.arraycopy(array, 0, newArr, 0, newsize);
        }

        return newArr;
    }

    public static String[] resizeArray(String[] array, int newsize) {
        if (null == array) {
            return null;
        }
        String[] newArr = new String[newsize];
        if (newsize > array.length) {
            System.arraycopy(array, 0, newArr, 0, array.length);
        } else {
            System.arraycopy(array, 0, newArr, 0, newsize);
        }

        return newArr;
    }

    public static Object[] resizeArray(Object[] array, int newsize) {
        if (null == array) {
            return null;
        }
        Object[] newArr = new Object[newsize];
        if (newsize > array.length) {
            System.arraycopy(array, 0, newArr, 0, array.length);
        } else {
            System.arraycopy(array, 0, newArr, 0, newsize);
        }

        return newArr;
    }
}