Question: I'm having a problem with this. It's only printing once, making a comparison between H < i. Help? public static ArrayList organizePrefixOrder(ArrayList a, ArrayList b)

I'm having a problem with this. It's only printing once, making a comparison between H < i. Help? public static ArrayList organizePrefixOrder(ArrayList a, ArrayList b) { int compared; if (a.size() == 0) { b.add(b.size(), a.get(0)); return b; } else { compared = byPrefixOrder().compare(a.get(0), a.get(1)); System.out.println(compared); if (compared > 1) { b.add(0, a.get(1)); a.remove(1); return organizePrefixOrder(a,b); } else if (compared == 1) { b.add(1, a.get(0)); b.add(2, a.get(1)); a.remove(0); a.remove(1); return organizePrefixOrder(a,b); } else { b.add(a.get(0)); a.remove(0); return organizePrefixOrder(a,b); } } } 
public static Comparator byPrefixOrder() { return new ComparatorByPrefixOrder(); } 
private static class ComparatorByPrefixOrder implements Comparator { @Override public int compare(Term a, Term b) { if (a.getSearched().charAt(0) == b.getSearched().charAt(0)) { System.out.println(a.getSearched().charAt(0) + "=" + b.getSearched().charAt(0)); return 0; } else if (a.getSearched().charAt(0) > b.getSearched().charAt(0)) { System.out.println(a.getSearched().charAt(0) + ">" + b.getSearched().charAt(0)); return -1; } else  System.out.println(a.getSearched().charAt(0) + "<" + b.getSearched().charAt(0)); return 1; } } 

Error:

1 How to Get Away with Murder

Exception in thread "main" 2 iZombie

3 Breaking Bad

8 Schussler Sucks More

4 Big Bang Theory

H

1

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:665)

at java.util.ArrayList.add(ArrayList.java:477)

at Term.organizePrefixOrder(Term.java:77)

at Term.main(Term.java:175)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!