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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -