I'm trying to alphanumerically sort a plate number (which is a string comprised of an alternating uppercase letter and digit) into an already sorted array. I'm; however, getting an array that has the same plate number as the one I'm trying to check.
Example: Plate Number to be sorted: U7I0L1
Plate Number List: A8M2M2, F4F1N4, N3N0G9
New List after using this code: U7I0L1 U7I0L1 U7I0L1
What does that code with all the } } } } } do? I am sure there will be much easier ways to do that. It looks so complicated that it could hide all sorts of errors without your being aware of them.
Are you sorting an array or inserting an element at a particular index? I have already made suggestions about insertion.
My answer assumes you want to practice coding 'from scratch' and implement your own algorithm.
I think you are starting with an array of Strings (sorted) with length 3 and then you are trying to produce an array of length 4 with one element having been inserted lexocographically.
This type of array cannot 'grow' to permit the insert you desire but you could copy the four elements to a different array. ( Or use an ArrayList , which can grow.)
It also looks like you are trying to write from scratch a lexicographic method simply to determine which string is greater. For that you might iterate over the two strings being compared: the charAt and an > operator could compare each character that you inspect.
The above code compares chars at index 0 and then index 1 but you would instead want a for loop to keep going, looking for the first character which is less, perhaps.
This will get you started and get rid of most the if statements in your code.
Your method will work nicely for Strings with so‑called asciibetical ordering, a jocular name for the same ordering as String's compareTo(String) method. Note there are other ways to compare Strings which you can find from the documentation. But your method can go wrong if the two Strings are different lengths. It would be a good idea to stop the loop as soon as a difference is found.
I am not quite sure what the idea behind this question is, whether it is necessary to write sorting algorithms or whether one can use ready‑made methods. I suspect that no sorting is actually required because the array is provided already sorted. I am not sure how the loop is supposed to work, but the many assignments in it look dubious to me. Look at lines 4, 5, 6. That sort of assignment is repeated throughout that loop. Please go through those assignments and work out what they will do to the array. I think that loop is beyond repair and you will have to start again. If you really need to sort arrays, writing a swap method, as Carey says, would be a good starting point.