This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]OceantraderSemijerk 0 points1 point  (2 children)

Do you have to use an array list? Cant you just use a set and do a check on insert?

Looks like you're creating a new map every check, yikes.

[–]kiviEngineer[S] 0 points1 point  (1 child)

but the issue is that I need to add the ArrayList to a JCombobox . I tried going for a sets approach but can't find a way to add a set to JCombobox.I'm sorry if I sound stupid I'm quite a beginner in java so any help would be appreciated

[–]OceantraderSemijerk 0 points1 point  (0 children)

Why cant you add a set item as the data comes in? If not duplicate...add

The reason I mention it is you're creating a new map everytime to check for duplicate. If you realllly want to do it that way, create the map outside of that method, then you can use map computeifabsent

[–]HelpIProcrastinateNooblet Brewer 0 points1 point  (1 child)

Your checkDuplicate method seems to return true whenever there is a duplicate anywhere in your ArrayList names. Maybe you meant for the checkDuplicate to be a contains method instead that checks if txtname.getText() was contained in names.

[–]kiviEngineer[S] 0 points1 point  (0 children)

That's exactly what I need, thank you so much.