Thread: how to update array into specified....

Forum : New To Java   27-12-2017 12:07:31 PM
User Image
Amritk

Newbie

Joined: May 8, 2017

Points: 230

Threads: 57

Posts: 211

how to update array into specified....

| Quote Date : Dec 27, 2017    Views:327    

how to update array into specified position?

int array[]={10,20,30,40,50};

index position=3
data=100


tags: array

Comments

User Image
Amritk

Newbie

Joined : May 8, 2017

Points : 230

Threads: 57

Posts: 211

Re: how to update array into specified....

Reply Date : Dec 27, 2017

Below code we will use to create Custome Arraylist to update the arraylist. 

<code>

public class UpdateArray{
  public static void main(String ar[]){
    int array[]={10,20,30,40,50,60};
   
    System.out.println("Before update"+ java.util.Arrays.toString(array));
     
    int value=500;?
      int copy[]=new int[array.length+1];

      int index=5;
      int j=0;
      boolean flag=false;
      for(int i=0;i<array.length;i++)
      {
        if(i==index)
          {
            for(j=copy.length-1;j>i;j--)
            {
              copy[j]=array[j-1];
             
            }
            flag=true;
          }
       
        if(flag==true)
          break;
        else
          copy[i]=array[i];
     
      }
      array=copy;
     array[j]=100;
      System.out.println(java.util.Arrays.toString(array));
   
    }
 }
</code>

Load More

No More Comments