Output strings from a set in lexicographical order
Just formal way :

Use TreeSet&lt;String&gt; ts to store S = {S1 U S2} : 


if String is already stored, it returns false,
you can use ts.toString() to print all values of the Set, separated by ', ' between '[]'
you have addAll(..), containsAll(..), retainAll(..), ... ready made [and optimized] other tools.
You can put in Collections.synchronizedSet(s) if you have multi threaded concurrrent jobs.


You can rebuilt/combine your code from JVM, not only from mathematical constraints. ... wheels exist from long time.