replace value in Array - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

replace value in Array

Demo Code


//package com.java2s;
import java.util.Arrays;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] arr = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        int startIndex = 2;
        int endIndex = 2;
        int value = 2;
        System.out.println(java.util.Arrays.toString(replaceArray(arr,
                startIndex, endIndex, value)));
    }//from   w w  w.jav a2 s .  co m

    public static int[] replaceArray(int[] arr, int startIndex,
            int endIndex, int value) {
        Arrays.fill(arr, startIndex, endIndex, value);
        return arr;
    }
}

Related Tutorials