2014-01-30 8 views
1
horse1ProgressionStr = Integer.toString(horse1Progression); 
    horse2ProgressionStr = Integer.toString(horse2Progression); 
    horse3ProgressionStr = Integer.toString(horse3Progression); 
    horse4ProgressionStr = Integer.toString(horse4Progression); 




    List<List<String>> list = Arrays.asList(Arrays.asList(horse1ProgressionStr, horse2ProgressionStr, horse3ProgressionStr, horse4ProgressionStr)); 
    for (List<String> l : list) { 
     Collections.sort(l); 
    } 
    Collections.sort(list, new Comparator<List<String>>() { 
     public int compare(List<String> o1, List<String> o2) { 
      return o1.get(0).compareTo(o2.get(0)); 
     } 
    }); 


    System.out.println("" + list); 


    List<List<String>> fourthHorse = list.subList(0, 2); 
    List<List<String>> thirdHorse = list.subList(2, 4); 
    List<List<String>> secondHorse = list.subList(4, 6); 

저는 4 개의 int를 순서대로 넣으려고했습니다. 그리고 그것들을 별도의 변수에 넣으려고했지만, 모든 방법으로 나에게 예외를 넘기는 것처럼 보입니다.subListString 인덱스가 범위를 벗어났습니다

예외 = 스레드에서

예외 "주요"java.lang.IndexOutOfBoundsException : toIndex의 = 2

+1

당신은 정확히 당신의'list' 안에 ** ** 하나 **'List'가 있습니다 –

답변

0

질문의 코드는 바로이 수행 지나치게 복잡하다 :

int[] horses = { horse1Progression, horse2Progression, 
       horse3Progression, horse4Progression }; 

// sort the input array in ascending order 
Arrays.sort(horses); 

// retrieve the elements in each position 
int first = horses[0]; 
int second = horses[1]; 
int third = horses[2]; 
int fourth = horses[3]; 
+1

고맙습니다. 나는 여러 해 동안 그것을 해왔습니다. – user3254808

+0

@ user3254808 여러분을 환영합니다! 이 답변으로 문제가 해결 되었다면 체크 표시를 클릭하여 [수락] (https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)하는 것을 잊지 마십시오. 왼쪽으로 ;) –

0

을 개체 list의 크기는 4이지만 인덱스 6 개까지 list.subList(4, 6)까지 목록을 검색하려고합니다.