a newly created UniqueItemCondition class for every element in a big list
would it result in bad performance?
I'm not sure it should - since java doesn't create copies of the set, but who knows..
Short answer: no, expected performance. No copies made by Java, passed by reference always. Some thoughts about what you're doing: 1. I see that you're only beginning it. The best thing you can do is to get any job where you can work with senior devs, and be guided in your learning. Sitting in vacuum and trying to learn on your own won't take you far. 2. Probably, what you assess as "very big" may be not that at all for the system, and actually depends on jvm params more than on your feelings. Such assumptions most often are very harmful in development, because you'll probably get into "premature optimization" (google that, it's a regular expression in software dev) 3. That separate class for "unique..." is something that makes my eyes bleed. Simple: if (!set.contains(str)) { is 10000 times more readable for Java devs and should be used there. There's no any benefit of seperating that in a class in this particular case. If you want to abstract away that condition, you do it in a wrong way, you should google for "strategy design pattern". 4. I don't see why you're mixing up lists and sets. Looks like you don't need lists. If you were working with sets only, it would be much simpler and clear 5. All that hassle may be simply written like public List<String> doSomething() { List<String> bigList = getBigList(); bigList.removeAll(inputSet); return bigList; } But I suggest to use better domain specific naming like: private Set<String> knownWords = loadKnownWords(); public List<String> findNewWords() { List<String> newWords = readAllWords(); newWords.removeAll(knownWords); return newWords; }
Even explained his/her situation
Обсуждают сегодня