java - How to create a sub array of objects from a given array? -


this question has answer here:

i have array 10 objects. created sub array of above array 2 objects. want java code create sub array remaining 8 objects.

for eg:

int[] a=[0,1,2,3,4,5,6,7,8,9] int[] b=[4,7]  

i want

int [] c=[0,1,2,3,5,6,8,9,] 

you use simple code this:

int[] c = new int[a.length - b.length]; //that is, assuming there no repeated elements int count = 0; main: (int = 0; < a.length; i++) {     (int j = 0; j < b.length; j++)         if (a[i] == b[j])            continue main; //the element should eliminated     c[count] = a[i];     count++; } 

if don't know size of results array, either use arraylist or create 1 teh same size of , ignore empty spaces.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -