Validating duplicate entries in a RecyclerView
I am trying to add the serial number in recycler view by using the add button.
need to check whether duplicate value trying to add in recycler view.
add button Onclick listener code are given below
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
// here need to check the duplicate values
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
serialNumberPojoList.add(serialNumberPojo);
RecyclerView recyclerView = view.findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
serialNumberAdapter.notifyDataSetChanged();
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
|
show 1 more comment
I am trying to add the serial number in recycler view by using the add button.
need to check whether duplicate value trying to add in recycler view.
add button Onclick listener code are given below
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
// here need to check the duplicate values
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
serialNumberPojoList.add(serialNumberPojo);
RecyclerView recyclerView = view.findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
serialNumberAdapter.notifyDataSetChanged();
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
1
You can check bycontainsor you can useHashSetlist which prevent duplicate values.
– Piyush
Nov 16 '18 at 11:16
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
1
You need to overrideequals()andhashcode()method in your pojo after thatcontainswill work.
– Piyush
Nov 16 '18 at 11:20
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00
|
show 1 more comment
I am trying to add the serial number in recycler view by using the add button.
need to check whether duplicate value trying to add in recycler view.
add button Onclick listener code are given below
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
// here need to check the duplicate values
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
serialNumberPojoList.add(serialNumberPojo);
RecyclerView recyclerView = view.findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
serialNumberAdapter.notifyDataSetChanged();
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
I am trying to add the serial number in recycler view by using the add button.
need to check whether duplicate value trying to add in recycler view.
add button Onclick listener code are given below
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
// here need to check the duplicate values
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
serialNumberPojoList.add(serialNumberPojo);
RecyclerView recyclerView = view.findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
serialNumberAdapter.notifyDataSetChanged();
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
edited Nov 16 '18 at 12:41
Fantômas
32.8k156491
32.8k156491
asked Nov 16 '18 at 11:14
S MugunthankumarS Mugunthankumar
276
276
1
You can check bycontainsor you can useHashSetlist which prevent duplicate values.
– Piyush
Nov 16 '18 at 11:16
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
1
You need to overrideequals()andhashcode()method in your pojo after thatcontainswill work.
– Piyush
Nov 16 '18 at 11:20
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00
|
show 1 more comment
1
You can check bycontainsor you can useHashSetlist which prevent duplicate values.
– Piyush
Nov 16 '18 at 11:16
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
1
You need to overrideequals()andhashcode()method in your pojo after thatcontainswill work.
– Piyush
Nov 16 '18 at 11:20
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00
1
1
You can check by
contains or you can use HashSet list which prevent duplicate values.– Piyush
Nov 16 '18 at 11:16
You can check by
contains or you can use HashSet list which prevent duplicate values.– Piyush
Nov 16 '18 at 11:16
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
1
1
You need to override
equals() and hashcode() method in your pojo after that contains will work.– Piyush
Nov 16 '18 at 11:20
You need to override
equals() and hashcode() method in your pojo after that contains will work.– Piyush
Nov 16 '18 at 11:20
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00
|
show 1 more comment
2 Answers
2
active
oldest
votes
You could do something like this:
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
}
And in SerialNumberPojo you need to implement your own equals() like:
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
SerialNumberPojo that = (SerialNumberPojo) other;
if (getId() != null && getId().equals(that.getId())) {
return true;
}
return false;
}
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
add a comment |
You can init Recycle View in onCreate function. Like:
@Override
public void onCreate(...) {
...
recyclerView = findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
...
}
and in your OnClickListener check for dublicate as write @Szymon Chaber
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
} else {
// your action if found duplicate value
}
serialNumberAdapter.updateData(serialNumberPojoList);
serialNumberAdapter.notifyDataSetChanged();
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
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%2f53336762%2fvalidating-duplicate-entries-in-a-recyclerview%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 could do something like this:
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
}
And in SerialNumberPojo you need to implement your own equals() like:
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
SerialNumberPojo that = (SerialNumberPojo) other;
if (getId() != null && getId().equals(that.getId())) {
return true;
}
return false;
}
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
add a comment |
You could do something like this:
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
}
And in SerialNumberPojo you need to implement your own equals() like:
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
SerialNumberPojo that = (SerialNumberPojo) other;
if (getId() != null && getId().equals(that.getId())) {
return true;
}
return false;
}
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
add a comment |
You could do something like this:
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
}
And in SerialNumberPojo you need to implement your own equals() like:
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
SerialNumberPojo that = (SerialNumberPojo) other;
if (getId() != null && getId().equals(that.getId())) {
return true;
}
return false;
}
You could do something like this:
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
}
And in SerialNumberPojo you need to implement your own equals() like:
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
SerialNumberPojo that = (SerialNumberPojo) other;
if (getId() != null && getId().equals(that.getId())) {
return true;
}
return false;
}
edited Nov 16 '18 at 12:10
answered Nov 16 '18 at 12:05
Szymon ChaberSzymon Chaber
620716
620716
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
add a comment |
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
Many Thanks for your timely support.
– S Mugunthankumar
Nov 16 '18 at 13:30
add a comment |
You can init Recycle View in onCreate function. Like:
@Override
public void onCreate(...) {
...
recyclerView = findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
...
}
and in your OnClickListener check for dublicate as write @Szymon Chaber
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
} else {
// your action if found duplicate value
}
serialNumberAdapter.updateData(serialNumberPojoList);
serialNumberAdapter.notifyDataSetChanged();
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
add a comment |
You can init Recycle View in onCreate function. Like:
@Override
public void onCreate(...) {
...
recyclerView = findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
...
}
and in your OnClickListener check for dublicate as write @Szymon Chaber
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
} else {
// your action if found duplicate value
}
serialNumberAdapter.updateData(serialNumberPojoList);
serialNumberAdapter.notifyDataSetChanged();
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
add a comment |
You can init Recycle View in onCreate function. Like:
@Override
public void onCreate(...) {
...
recyclerView = findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
...
}
and in your OnClickListener check for dublicate as write @Szymon Chaber
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
} else {
// your action if found duplicate value
}
serialNumberAdapter.updateData(serialNumberPojoList);
serialNumberAdapter.notifyDataSetChanged();
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
You can init Recycle View in onCreate function. Like:
@Override
public void onCreate(...) {
...
recyclerView = findViewById(R.id.serial_recycle);
serialNumberAdapter = new SerialNumberAdapter(serialNumberPojoList, view.getContext(), ScannedDetailsFragment.this);
mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(serialNumberAdapter);
...
}
and in your OnClickListener check for dublicate as write @Szymon Chaber
serialNumberAddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!serialNumberField.getText().toString().equals("")) {
SerialNumberPojo serialNumberPojo = new SerialNumberPojo(serialNumberField.getText().toString());
if (!serialNumberPojoList.contains(serialNumberPojo)) {
serialNumberPojoList.add(serialNumberPojo);
} else {
// your action if found duplicate value
}
serialNumberAdapter.updateData(serialNumberPojoList);
serialNumberAdapter.notifyDataSetChanged();
actualQuantity.setText(String.valueOf(serialNumberAdapter.getItemCount()));
} else {
messageDialog.showAlertDialogBox(getContext(), "Add or Scan Serial Number", "error");
}
}
});
answered Nov 16 '18 at 12:20
OnixOnix
4579
4579
add a comment |
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%2f53336762%2fvalidating-duplicate-entries-in-a-recyclerview%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
You can check by
containsor you can useHashSetlist which prevent duplicate values.– Piyush
Nov 16 '18 at 11:16
serialNumberPojoList has the custom datatype pojo class, I tried with contains but not work
– S Mugunthankumar
Nov 16 '18 at 11:19
1
You need to override
equals()andhashcode()method in your pojo after thatcontainswill work.– Piyush
Nov 16 '18 at 11:20
public boolean equals(Object obj) { return super.equals(obj); } public int hashCode() { return super.hashCode(); } I have implemented this in pojo class is that ok or need code on this methods
– S Mugunthankumar
Nov 16 '18 at 11:46
You need to implement actual code there, e. g. public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerialNumberPojo that = (SerialNumberPojo) o; return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
– Szymon Chaber
Nov 16 '18 at 12:00