Groovy web console

subscribe to the feed Subscribe
to this
site

copy byte arrays

Published 1 month ago by Ram with tags byte arrays
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.Arrays; 

public class ArrayDemo {    
    public static void main(String[] args) {  
    // intializing an array arr1 
    String str = "Rama"
    byte[] arr1 = str.getBytes();      // printing the array       
    System.out.println("Printing 1st array:"+ arr1);       
   // for (int i = 0; i < arr1.length; i++) {          
       // System.out.println(arr1[i]);         
   // }        // copying array arr1 to arr2 with newlength as 5       
        byte[] arr2 = Arrays.copyOf(arr1, arr1.length + 1);       
        //arr2[3] = 70;       arr2[4] = 45;        // printing the array arr2       
        System.out.println("Printing new array:" + arr2);       
    //    for (int i = 0; i < arr2.length; i++) {          
        //System.out.println(arr2[i]);       
   // }    
} 
}