Basically I need to read numbers from a file into a existing array, but while doing this I need to also sort the numbers being added into their appropriate numerical position in descending order. While also checking to see if any of the number being loaded exist and if they do excluding them from the load. If there is anything that I need to provide please let me know.
Asked
Active
Viewed 48 times
-3
-
The array contains only numbers which occur only once in your file in descending order? – Flown Sep 03 '15 at 17:59
-
You need to provide us with some effort and a specific problem. Please see how to ask: http://stackoverflow.com/help/how-to-ask – tnw Sep 03 '15 at 18:00
-
Check out the accepted answer for this question: http://stackoverflow.com/questions/8725387/why-is-there-no-sortedlist-in-java – reden Sep 03 '15 at 18:01
-
yes the array only contains numbers which can only occur once in the array. The file contains some duplicates of the existing array's numbers and some new numbers. – Chad.S Sep 03 '15 at 18:01
1 Answers
0
You could use a tree set. http://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html
If you have to use an array, try using binary search to find the element or the position the element should be at (the while
loop commonly used exits in both cases, providing you one index in the array). See http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#binarySearch(int[],%20int).
Unfortunately, that's about all the detail I can provide. Please provide more details to get more details. Code snippets are welcome here but don't put too much.

Heman Gandhi
- 1,343
- 9
- 12