Notice
Recent Posts
Recent Comments
Link
kimmgamjja
[Java] Collections.swap()으로 요소 위치 바꾸기 본문
728x90
* Collection
Collections.swap( list, index1, index2 )
Collections.swap( list, index1, index2 ) 는 리스트에서 index1과 index2의 위치를 바꾼다
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Example {
public static void main(String[] args) {
List<String> words = Arrays.asList("A", "B", "C", "D");
Collections.swap(words, 0, 3);
System.out.println(words); // [D, B, C, A]
}
}
- 배열에서 Collections.swap()으로 요소의 위치 바꾸기
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Example1 {
public static void main(String[] args) {
String[] words = {"A", "B", "C", "D"};
Collections.swap(Arrays.asList(words), 0, 3);
System.out.println(Arrays.toString(words)); // [D, B, C, A]
}
}
https://crazykim2.tistory.com/557
[JAVA] 컬렉션(Collection)이란?(추가 : Collecion의 요소 상세설명)
안녕하세요 이번 포스팅에서는 자바의 컬렉션(Collection)에 대해서 알아보겠습니다 Collection은 많이 사용되지만 정확하게 어떤 것인지는 저도 모른채로 사용을 했습니다 이번 포스팅을 하면서 제
crazykim2.tistory.com
728x90
'공부 > Java' 카테고리의 다른 글
[Java] stream sorted(정렬), 람다 표현식 (1) | 2025.02.28 |
---|---|
[Java] Exception>java.lang.NumberFormatException++Exception Message>For input string: "10000000000"++Stack Trace>java.lang.NumberFormatException: For input string: "10000000000" (1) | 2025.02.14 |
[Java] String.valueOf()와 Object.toString() (0) | 2025.01.23 |
[Java] 자바 스케줄링 Scheduling 하는 방법 (0) | 2025.01.23 |
[Java] Callable Runnable (2) | 2025.01.22 |