Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Adding all elements of one array to another

$
0
0
Lets say you have array arr1 = {2,3,4,null,null,null,null} and..
arr2 = {6,7,8}
What I want to do is to add the arr2 to arr1 on top of the stack so that after the addAll method arr1 would look like..

arr1 = {2,3,4,6,7,8,null} and arr2 would be empty. I know using an arrayList would more than likely be easier but I am trying to understand the logic of using multiple for loops to iterate through both arrays. The method looks like this.

public Bag addAll(Bag b1);

The Bag is a class with a constructor:
Bag(int size){
		counter = 0;
		count_ItemsRemoved = 0;
		count_ItemsRandomlyRemoved = 0;
		collect = new Object[size];
	}

Any help would be greatly appreciated!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>