public static long add2(List list) { long start = System.currentTimeMillis(); for(int i= 0; i < 1000; i++) list.add(500, "X"); long end = System.currentTimeMillis(); return end-start; }
4번쨰 라인에서 에러가 발생.
지금 현재 쓰고 있는 jdk 는 1.8버전인데
저 형식은 예전 1.5에서 쓰던 형식,
| add(int index, E element) Inserts the specified element at the specified position in this list (optional operation). |
1.5 api를 찾아보고 있을줄이야..
0번지에서 999번지까지 돌동안 500에 "X"라는 데이터를 넣으려는 의도는 아닌것 같아서 수정함.
현재 내가 쓰는 1.8 버전에 맞게
public static long add2(List list) { long start = System.currentTimeMillis(); for(int i= 0; i < 1000; i++) list.add(500+"", i); long end = System.currentTimeMillis(); return end-start; }
이상없이 실행됨.
인줄 알았으나, 굳이 i를 넣을필요가 없음 왜냐하면 500번지에 계속 추가하면 뒤에 번지 데이터들은 자동적으로 밀리게 될 터이니. 다시한번 맞게 수정한다면,
public static long add2(List list) { long start = System.currentTimeMillis(); for(int i= 0; i < 1000; i++) list.add("X", 500); long end = System.currentTimeMillis(); return end-start; }
이정도가 될듯
과거의 버전의 API도 일하다보면 한두번은 더 찾아볼 기회아닌 기회가 오겠지...
위에는 모두 헛소리고, 임포트를 이상하게 해서 였음... util.Array가 아닌 따른녀석을 임포트한 내가 흑우요!!
'Programming > Java' 카테고리의 다른 글
실생활에서 쓸수있을만한 객체기반 반복문, 조건문 예제. (0) | 2019.03.07 |
---|---|
Vector 공부하던중 ArrayIndexOutOfBoundsException 에 대하여. (0) | 2019.01.16 |
Calendar class 활용하기 (0) | 2018.12.31 |
Integer를 이용한 진법바꾸기로 간단한 예제 만들기 (0) | 2018.12.31 |
Integer를 이용하여 진법변환하기 (0) | 2018.12.31 |