get non duplicate items from arraylist [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Need help! I have a Json file with string values. By clicking on the button, I put a random string from this file into the arraylist. But I shouldn't put duplicate elements in the arraylist. How can i do this? Thank you in advance.

Use a Set instead of a List. It does not allow duplicates. You can get more detailed information in the reference documentation: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Set.html.

Related

How to an Array List from least to greatest? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to make an arraylist that has random numbers and make it in order from least to greatest.
How do I do this?
Try using the
Collections.sort(your_array_name)
This sorts your array from least to greatest in place.
If you still want some more information, try this link:
https://www.geeksforgeeks.org/collections-sort-java-examples/

How to store user data and when the data is repeated it should show error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Example
if there are 4 slots named A1,B1,C1,D1. If first user enters A1 and when the second user enter the same slot it should error it has already been chosen.
The built-in class java.util.HashMap can do that. Read the docs, perhaps search for some usage examples :)

Checking if one list contains all elements of another element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to check if a List of characters like {a,a,d,e} is contained in a list like {a,d,e} in java. I want the answer to be false but I have no idea how to go about doing this. All help would be appreciated :)
Try using the retainAll() method and check for the result. col1.retainAll(col2) leaves all elements in col1 that are also in col2. If the size of col1 is the same before and after the call, the whole col2 is contained.

How to Create Strings Programatically in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So I am creating a program that need to create as many strings and integers as the user says. The amount is stored in wordlength, and I need to create these strings programmatically based on the input. Can somebody help me?
First, ask the user to input how many strings to store. This can be done through a Scanner.
Then, make an array of type String with length equal to the user input number.
Then, fill in the array through a Scanner with a for loop.
I hope next time you search about you problem before you write a question about it.

How to manage Continuous Changing values in an array of strings [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an array of strings but the values in array is changing continuously changing.
Is there any other way of managing the array except removing items and changing index locations?
public int[] deviceId=null;
deviceId=new String[deviceCount];
in my case deviceCount is changing as new device comes. so i continuously need to change array size and add or remove items
Java offers a really handy mechanism known as the ArrayList. It's a dynamic array that you can use to do what you're describing.
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

Categories