I am new to java.
I am trying to sort an ArrayList array from String using String.compareTo() .
I compiled the code so that the output is:
Causality, is, relationship
This is also called causal.
This, is, oh, and, the reason, and her, affect
Now I want to sort this code (lexicographically) so that the output is:
Causality, and, this, relationship
This, also called a causal relationship, is
This, oh, oh, affect, and the reason, this, it
However, I am generating some crazy output.
My code is below.
Any help would be appreciated.
I worked on this, probably a very simple problem for several hours, and I am ready to destroy my computer. Thanks
public class Wk5Q5 { void process1 () { String s1 = "Causality is a relationship"; String s2 = "It is also called causation"; String s3 = "It is about a cause and its affect"; ArrayList<String[]> list = new ArrayList<String[]>(); String[] arr1 = s1.split(" "); list.add(arr1); String[] arr2 = s2.split(" "); list.add(arr2); String[] arr3 = s3.split(" "); list.add(arr3); for(int i = 0; i < list.size(); i++){ for (int j = 0; j < list.get(i).length; j++){ String t = list.get(i)[j]; if (j > 0){ t = ", " + t; } System.out.print(t);