get the duplicates values from Arraylist and then get those items in another Arraylist
I have an arraylist which contains some values with duplicates i want to collect those values into another Arraylist....
like
Arraylist<String> one; //contains all values with duplicates
one.add("1");
one.add("2");
one.add("2");
one.add("2");
Here, I want to get all the duplicates values in another arraylist...
Arraylist<String> duplicates; //contains all duplicates values which is 2.
I want those values which counts greater or equals 3.....
Currently, I don't have any solution for this please help me to find out
java android arraylist collections
add a comment |
I have an arraylist which contains some values with duplicates i want to collect those values into another Arraylist....
like
Arraylist<String> one; //contains all values with duplicates
one.add("1");
one.add("2");
one.add("2");
one.add("2");
Here, I want to get all the duplicates values in another arraylist...
Arraylist<String> duplicates; //contains all duplicates values which is 2.
I want those values which counts greater or equals 3.....
Currently, I don't have any solution for this please help me to find out
java android arraylist collections
1
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of typeString
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of theequals
method or by some other criteria? Please clarify this question and also add sample input and expected output.
– Federico Peralta Schaffner
Jan 2 at 14:03
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12
add a comment |
I have an arraylist which contains some values with duplicates i want to collect those values into another Arraylist....
like
Arraylist<String> one; //contains all values with duplicates
one.add("1");
one.add("2");
one.add("2");
one.add("2");
Here, I want to get all the duplicates values in another arraylist...
Arraylist<String> duplicates; //contains all duplicates values which is 2.
I want those values which counts greater or equals 3.....
Currently, I don't have any solution for this please help me to find out
java android arraylist collections
I have an arraylist which contains some values with duplicates i want to collect those values into another Arraylist....
like
Arraylist<String> one; //contains all values with duplicates
one.add("1");
one.add("2");
one.add("2");
one.add("2");
Here, I want to get all the duplicates values in another arraylist...
Arraylist<String> duplicates; //contains all duplicates values which is 2.
I want those values which counts greater or equals 3.....
Currently, I don't have any solution for this please help me to find out
java android arraylist collections
java android arraylist collections
edited Jan 3 at 11:38
Vipul Chauhan
asked Jan 2 at 13:26
Vipul ChauhanVipul Chauhan
3810
3810
1
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of typeString
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of theequals
method or by some other criteria? Please clarify this question and also add sample input and expected output.
– Federico Peralta Schaffner
Jan 2 at 14:03
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12
add a comment |
1
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of typeString
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of theequals
method or by some other criteria? Please clarify this question and also add sample input and expected output.
– Federico Peralta Schaffner
Jan 2 at 14:03
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12
1
1
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of type
String
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of the equals
method or by some other criteria? Please clarify this question and also add sample input and expected output.– Federico Peralta Schaffner
Jan 2 at 14:03
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of type
String
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of the equals
method or by some other criteria? Please clarify this question and also add sample input and expected output.– Federico Peralta Schaffner
Jan 2 at 14:03
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12
add a comment |
2 Answers
2
active
oldest
votes
You can use a set for this:
Set<String> set = new HashSet<>();
List<String> duplicates = new ArrayList<>();
for(String s: one) {
if (!set.add(s)) {
duplicates.add(s);
}
}
You just keep adding all the elements to the set. If method add()
returns false, this means the element was not added to set i.e it already exists there.
Input: [1, 3, 1, 3, 7, 6]
duplicates: [1, 3]
EDITED
For the value which counts 3 or greater, you can use streams to do it like so:
List<String> collect = one.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() >= 3)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Basically you collect you initial list in a map, where key
is the string and value
is the count. Then you filter this map for values that have count greater than 3, and collect it to the result list
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
add a comment |
You could also do this via a stream:
List<String> duplicates = one.stream()
.collect(Collectors.groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));
I would prefer something likeone .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
@Eritrean UsingCollections.frequency
for each element of the stream turns the complexity of the solution toO(n^2)
, which is highly undesirable.
– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007206%2fget-the-duplicates-values-from-arrayliststring-and-then-get-those-items-in-ano%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a set for this:
Set<String> set = new HashSet<>();
List<String> duplicates = new ArrayList<>();
for(String s: one) {
if (!set.add(s)) {
duplicates.add(s);
}
}
You just keep adding all the elements to the set. If method add()
returns false, this means the element was not added to set i.e it already exists there.
Input: [1, 3, 1, 3, 7, 6]
duplicates: [1, 3]
EDITED
For the value which counts 3 or greater, you can use streams to do it like so:
List<String> collect = one.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() >= 3)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Basically you collect you initial list in a map, where key
is the string and value
is the count. Then you filter this map for values that have count greater than 3, and collect it to the result list
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
add a comment |
You can use a set for this:
Set<String> set = new HashSet<>();
List<String> duplicates = new ArrayList<>();
for(String s: one) {
if (!set.add(s)) {
duplicates.add(s);
}
}
You just keep adding all the elements to the set. If method add()
returns false, this means the element was not added to set i.e it already exists there.
Input: [1, 3, 1, 3, 7, 6]
duplicates: [1, 3]
EDITED
For the value which counts 3 or greater, you can use streams to do it like so:
List<String> collect = one.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() >= 3)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Basically you collect you initial list in a map, where key
is the string and value
is the count. Then you filter this map for values that have count greater than 3, and collect it to the result list
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
add a comment |
You can use a set for this:
Set<String> set = new HashSet<>();
List<String> duplicates = new ArrayList<>();
for(String s: one) {
if (!set.add(s)) {
duplicates.add(s);
}
}
You just keep adding all the elements to the set. If method add()
returns false, this means the element was not added to set i.e it already exists there.
Input: [1, 3, 1, 3, 7, 6]
duplicates: [1, 3]
EDITED
For the value which counts 3 or greater, you can use streams to do it like so:
List<String> collect = one.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() >= 3)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Basically you collect you initial list in a map, where key
is the string and value
is the count. Then you filter this map for values that have count greater than 3, and collect it to the result list
You can use a set for this:
Set<String> set = new HashSet<>();
List<String> duplicates = new ArrayList<>();
for(String s: one) {
if (!set.add(s)) {
duplicates.add(s);
}
}
You just keep adding all the elements to the set. If method add()
returns false, this means the element was not added to set i.e it already exists there.
Input: [1, 3, 1, 3, 7, 6]
duplicates: [1, 3]
EDITED
For the value which counts 3 or greater, you can use streams to do it like so:
List<String> collect = one.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() >= 3)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Basically you collect you initial list in a map, where key
is the string and value
is the count. Then you filter this map for values that have count greater than 3, and collect it to the result list
edited Jan 3 at 11:48
answered Jan 2 at 13:31
Schidu LucaSchidu Luca
3,040522
3,040522
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
add a comment |
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
thanks for the answer but can you please read the updated question and sorry for the last incomplete question.....
– Vipul Chauhan
Jan 3 at 11:40
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
@VipulChauhan edited
– Schidu Luca
Jan 3 at 11:49
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
it is give me some errors like Lambada expression, Method references, Static Interface Method Calls are not supported in language 1.7 in these lines (e -> e.getValue() >= 3......Map.Entry::getKey.....Function.identity()) also require minimum Api level 24
– Vipul Chauhan
Jan 4 at 8:14
1
1
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
It means that you have java 7. In this version lambdas are not supported
– Schidu Luca
Jan 4 at 8:25
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
actually i have java 8 but android studio supports java 7 now i set the compiler to 1.8 thanks but this answer is not suitable for me because it requires the minimum android version nougat
– Vipul Chauhan
Jan 4 at 9:58
add a comment |
You could also do this via a stream:
List<String> duplicates = one.stream()
.collect(Collectors.groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));
I would prefer something likeone .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
@Eritrean UsingCollections.frequency
for each element of the stream turns the complexity of the solution toO(n^2)
, which is highly undesirable.
– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
add a comment |
You could also do this via a stream:
List<String> duplicates = one.stream()
.collect(Collectors.groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));
I would prefer something likeone .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
@Eritrean UsingCollections.frequency
for each element of the stream turns the complexity of the solution toO(n^2)
, which is highly undesirable.
– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
add a comment |
You could also do this via a stream:
List<String> duplicates = one.stream()
.collect(Collectors.groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));
You could also do this via a stream:
List<String> duplicates = one.stream()
.collect(Collectors.groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));
answered Jan 2 at 13:41
AomineAomine
42.4k74575
42.4k74575
I would prefer something likeone .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
@Eritrean UsingCollections.frequency
for each element of the stream turns the complexity of the solution toO(n^2)
, which is highly undesirable.
– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
add a comment |
I would prefer something likeone .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
@Eritrean UsingCollections.frequency
for each element of the stream turns the complexity of the solution toO(n^2)
, which is highly undesirable.
– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
I would prefer something like
one .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
I would prefer something like
one .stream() .distinct() .filter(i->Collections.frequency(one, i)>1) .collect(Collectors.toCollection(ArrayList::new));
– Eritrean
Jan 2 at 13:51
3
3
@Eritrean Using
Collections.frequency
for each element of the stream turns the complexity of the solution to O(n^2)
, which is highly undesirable.– Federico Peralta Schaffner
Jan 2 at 13:58
@Eritrean Using
Collections.frequency
for each element of the stream turns the complexity of the solution to O(n^2)
, which is highly undesirable.– Federico Peralta Schaffner
Jan 2 at 13:58
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
please read the updated question and sorry for the last one. It is too complex to implement by the fresher can you give me an another answer or explain this....thanks for your contribution
– Vipul Chauhan
Jan 3 at 11:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007206%2fget-the-duplicates-values-from-arrayliststring-and-then-get-those-items-in-ano%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please explain your problem with input and required output.
– Mukesh prajapati
Jan 2 at 13:30
Why a list with the duplicates? After all, the duplicate elements are all equal, it doesn't make much sense with elements of type
String
... Do you need all the duplicates, or just the ones that are repeated (i.e. all but the first occurrences)? Besides, you're not telling us when 2 elements are considered equal. Is it by means of theequals
method or by some other criteria? Please clarify this question and also add sample input and expected output.– Federico Peralta Schaffner
Jan 2 at 14:03
Shared a generic utility to solve for a value n, for the number of occurrence of an element. Do take a look at it, hope it would help.
– Naman
Jan 2 at 17:12