This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Java Remove Duplicates from an Array?
String={3333,4444,5555,5555,1111}
Using Delimiter i have put the String values in an array[]..
Now, How can i remove the same entries in an Array???
Use Set instead, Or use temporarily Set and get the unique result back to array
See
What interface in Java can I use to store unique objects?
Related
This question already has answers here:
How to use subList()
(6 answers)
Closed 3 years ago.
I want to pass an array as argument to a function without first element.
I came up with this solution, but I'm wondering if there are better ways to it.
List<Integer> numbers = new ArrayList<>();
//... in the meantime numbers is an array that contain 1000 elements;
numbers.remove(0);
myFunction(numbers)
You can use subList(firstElement, lastElement); method.
Here please check javadoc.
This question already has answers here:
Java ArrayList copy
(10 answers)
Closed 6 years ago.
I have two ArrayList variables
first
ArrayList listOrders;
the second is
ArrayList selectedOrders = listOrders;
The problem is when i deleting listOrders it's clear selectedOrders value.
Is there a way to store value after deleting his parent?
If you want to hold 2 different references with the same data do:
ArrayList selectedOrders = new ArrayList<>(listOrders);
This question already has answers here:
How can I check if a single character appears in a string?
(16 answers)
Closed 9 years ago.
I have a string like :
"\"[\"a\",\"b\", \"c\"]\""
How to convert this to a list of strings
Could you suggest me a nice way of doing it in Java?
str.contains("c") does this job. However did not you think to consult String class documentation first?
Use contains():
if (str.contains("\"c\""))
This question already has answers here:
Generating Unique Random Numbers in Java
(21 answers)
Closed 9 years ago.
What would be the best way to generate 50,000 unique random values which are put into an ArrayList in Java?
Fill the ArrayList with 50,000 sequential values and call Collections.shuffle(list).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
In Java, how can I test if an Array contains a certain value?
I want to check for a string S whether it is present in string array or not. Is there any direct method to do so ?
EDIT
If the answer excludes the use of List then that would be better.
There are a couple of ways to accomplish this using the Arrays utility class.
If the array is not sorted:
java.util.Arrays.asList(theArray).indexOf(o)
If the array is sorted, you can make use of a binary search for performance:
java.util.Arrays.binarySearch(theArray, o)
See here Where is Java's Array indexOf?
You can convert it to List and check: Arrays.asList(arrayVariable).contains(S)