Question, sir: Could you use these methods to sort a 2D string array so that the array elements are sorted from A to Z? I have seen some videos related to this, but not exactly what I need. I have a project concerning this and for some reason, there is one piece that is giving me a bit of trouble. This is some of the relevant code right here: for(int i=0; i>numberOfRows; i++) { if(statesCapitals[i].compareToIgnoreCase(statesCapitals[i-1]) > 0) { temp = statesCapitals[i]; statesCapitals[i] = statesCapitals[i-1]; statesCapitals[i - 1] = temp; } My compareToIgnoreCase is giving me an error: Cannot invoke compareToIgnoreCase(String[]) on the array type String[]. I'm not exactly sure what's wrong with the code since both elements are strings. Any help would be appreciated! Thanks!
For a 2D array, you would loop through each element and sort it, since each element is also an array. Since you are working with Strings, you can just use the Comparator sort() method
Please SUBSCRIBE! More programming videos coming soon! ✌️
Thank you
And if i want compare 3 strings: for example: "kali, karkiv, karola" ? How can i do it at the same time? and how put in order in a list?
Use && for compound expressions. Then use arrays or ArrayList to store them in a list. I have videos on both
@@Appficial , oh thank you a lot. I will try to find this videos :)
where are those videos?@@Appficial
Great video!
Thanks Ralph!
Thank u ❤️
Question, sir: Could you use these methods to sort a 2D string array so that the array elements are sorted from A to Z? I have seen some videos related to this, but not exactly what I need. I have a project concerning this and for some reason, there is one piece that is giving me a bit of trouble.
This is some of the relevant code right here:
for(int i=0; i>numberOfRows; i++) {
if(statesCapitals[i].compareToIgnoreCase(statesCapitals[i-1]) > 0) {
temp = statesCapitals[i];
statesCapitals[i] = statesCapitals[i-1];
statesCapitals[i - 1] = temp;
}
My compareToIgnoreCase is giving me an error: Cannot invoke compareToIgnoreCase(String[]) on the array type String[].
I'm not exactly sure what's wrong with the code since both elements are strings. Any help would be appreciated! Thanks!
For a 2D array, you would loop through each element and sort it, since each element is also an array. Since you are working with Strings, you can just use the Comparator sort() method
@@Appficial Thank you for the help, sir!