java - Comparing two arraylists unequal sizes - heap issue post comparison -
java - Comparing two arraylists unequal sizes - heap issue post comparison -
i comparing 2 arraylist<string>
average size of list one, 50k
, , list two, 200k
.
int size = mssqllist.size(); (int index = 0; index < size; index++) { if (!oraclesqllist.contains(mssqllist.get(index))) { logger.debug(" *[possible miss]* oracle missing record id: " + (mssqllist.get(index))); } }
the list have info in string 16 chararcters, i.e. a89eerdd12312445 etc... running collection.sort(list)
on both before entering above loop.
the average comparing times close 160 seconds. best approach or can much better?
question 2: results have guessed beingness fetched db, 5 day interval.
ideally can 1.1 1000000 records if take 30 days interval. old array list implementation throwing outofmemory due load.
so quick follow question can force load 1.1 1000000 ,30 day interval ?
your biggest problem contains()
o(n), because iterates through list until gets nail (average iterations n/2), of course of study performs poorly.
also, sorting list nil useful performance.
the humble hashset
friend: has o(1) performance of operations.
using set lets in few lines:
set<string> set = new hashset<>(oraclesqllist); (string s : mssqllist) if (!set.contains(s)) logger.debug(" *[possible miss]* oracle missing record id: " + s);
the above code should finish in fraction of second.
java sorting arraylist collections
Comments
Post a Comment