Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to extend array after initialization by creating an new array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 310
    Comment on it

    In the below example I have created extend array function. Here first I have define array length then extend new array value. You can see below program it will clearly describe to extend  array after initialization by creating an new array.

    public class Main {
       public static void main(String[] args) {
          String[] names = new String[] { "A", "B", "C" };
          //Define array length
    
          String[] extended = new String[7];
    
        //extend new array
    
          extended[3] = "D";
          extended[4] = "E";
          extended[5] = "F";
          extended[6] = "G";
        //  check value and length 
    
          System.arraycopy(names, 0, extended, 0, names.length);
          for (String str : extended){
             System.out.println(str);
          }
       }
    }
    
    
    
    
         output :  A
                   B
                   C
                   D
                   E
                   F
                   G

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: