Remove Last Element from Array using Java

Arrays.copyOf method

package app;

import java.util.Arrays;

public class Main
{
    public static void main(String[] args)
    {
        Integer[] data = {10, 3, 17, 50, 15};
        data = Arrays.copyOf(data, data.length - 1);

        System.out.println(Arrays.toString(data));
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.