tags:

views:

40

answers:

2

So I have an array of strings (let's call it array1) and then I have another array (array2 say) and I want to check if array2 is a subset of array1.. is there a simple command for that?

edit:

scenario2

I have array1 (which is user generated through an edittext with strings say names of people) and I have a matrix that I want to check to see if each individual row is a subset of array1.. for example.. array1 = "bob" , "john" , "joe" , "frank" and I have a 2x3 matrix with names in each of 6 items of it and I want to check if each row is a subset of array1.. so if row1 of the matrix was equal to "jim" , "joe" , "frank" and row2 was equal to "joe" , "bob" , "frank" then only row2 would be a subset of array1

A: 

It depends on how big the array is, but if it's not very big you can just loop for each element in array2, whether it exists in array2.

Note that this is true if the arrays are sets (i.e. no duplicate value and the ordering does not matter). I assume they are since you are talking about subsets

Louis Rhys
Well I was thinking each array wouldn't have more than 15 or 20 items in each so a loop would work moderately quickly.. however I was actually planning on array2 being technically each row of a matrix (which would be a loop itself converting it for each compare which I haven't even figured how to do yet either lol) and comparing each row with array1.. with regards to the uniqueness of the items in the arrays I'm not sure.. I was planning on having array1 be user generated by inputting strings and they could enter as many as they wanted so I planned
dootcher
planned on array1 being set to "" "" "" etc and replacing each with a user entered string as they input them and then comparing array2 (or each row of the matrix whatever) to see if its a subset of array1
dootcher
so, you have two dimensional arrays? what exactly do you mean by subset?
Louis Rhys
Ok to explain completely (which I proly should have done in the first place lol) I have array1 (which is user generated with strings say names of people) and I have a matrix that I want to take each row of it and check to see if array1 is a subset of it.. for example.. array1 = "bob" , "john" , "joe" , "frank" and I have a 3x3 matrix with names in each of 9 items of it and I want to check if each row is a subset of array1.. if row2 was equal to "bob" , "joe" , "frank" it would be a subset of array1
dootcher
Sorry typo.. I want to see if each row is a subset of array1
dootcher
+1  A: 

You can but both arrays into separate HashSets and then call containsAll on array1's set with array2's set.

Qberticus
i'm not sure how to use hashsets but the containsall seems to be exactly what im looking for.. can containsall be used in doing the scenario ive discussed in the new scenario i added above with my edit?
dootcher