java - Mocking contains() with a String[][] -
i have 2 sql tables. after grabbing both tables in resultsets, i've stored them in string[][]s, ordered common id column. these tables should contain same data, 1 may have duplicates of same row other. in order check if every string[] in table present @ least once in table b, need construct efficient contains()-esque method string[].
this have far, stumped (also not sure if there's more efficient solution). give source table , target table. takes each string[] in source table , (should) go through each string[] in target table , find instance of source string[] somewhere in target string[][] checking if there's @ least 1 string[] matches original string[], element element. can point me in right direction and/or fill in blanks? isn't homework or assignment, i'm refactoring code , having major brain fart. thanks!
public boolean targetcontainssource(string[][] s, string[][] t) { boolean result = true; //for each string[] in string[][] s (int = 0; < s.length; i++) { //for each string[] in string[][] t (int j = 0; j < t.length; j++) { //for each string in t's string[] (int k = 0; k < t[0].length; k++) { if (!s[i][k].equals(t[j][k])) { } } } } return result; }
your innermost loop removed using arrays.equals().
for each element of first array, should define found boolean variable, set true once element found in second array. once second loop finished, if variable still false, have found element of first array not in second, , can return immediately.
and of course, variable set true, can break out of second loop.
Comments
Post a Comment