java - Hashset implementation output -
for block of code asked explain how output different input:
does difference have string object being passed in , string literal being returned?
import java.util.*; public class c { public static void main(string[] args) { set<string> s = new hashset<string>(); (string : args) if (!s.add(a)) system.out.println("here: " + a); system.out.println(s.size() + " there: " + s); } }
the add(..)
function returns false if string same contents present in hashset
(and duplicate not added). hence, if (!s.add(a))
true, if duplicate strings present in args
; s.size() <= args.length
.
Comments
Post a Comment