Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 16일차
2024. 12. 9. 17:06ㆍKosta 클라우드 네이티브 어플리케이션 개발(CNA) 교육
JAVA
public class chap11_collections {
public static void main(String[] args) {
// <E> : list안에 들어가 있는 값의 타입
// generic type : list 선언/생성시 타입을 명시
List<Integer> arr = new ArrayList<>();
arr.add(1);
arr.add(2);
arr.add(3);
arr.add(4);
arr.add(5);
arr.add(6);
// arr.stream().forEach(System.out::print);
System.out.println();
/*
* list 데이터 지우기 removeAll -> 만약 삭제할 데이터가 없다면 NullPointException 반환 clear -> 만약
* 삭제할 데이터가 없다면 UnsupportedOperationException 반환
*/
// arr.removeAll(arr);
// arr.stream().forEach(System.out::print);
List list = new ArrayList(); // P p = new C();
list.add("hong");
ArrayList alist = new ArrayList(); // P p = new C()
// Lamda : 익명함수, 일회용 함수, Anonymous function
arr.forEach(str -> {
System.out.print(str);
});
canSel();
arr.stream().forEach(System.out::print);
canSel();
/*
* 동기화 ( synchronized )
* - 요청 후 응답이 올때까지 다른 요청을 허용하지 않는 처리 방식
*
*/
List<String> vlist = new Vector<>();
vlist.add("A");
vlist.add("B");
vlist.add("C");
vlist.add("D");
vlist.forEach(str -> {
System.out.print(str);
});
canSel();
/*
* 직렬화(serialization) / 역직렬화(Deserialization)
* - 전송할 수 있는 형태(바이트)로 개체 상태를 (변환)하는 프로세스
* - Vector(동기) --- ArrayList(비동기) ***** 순서O, 중복O
* - 스트림(Stream)
* - transient : 직렬화 대상에서 제외
*
* CF : 인스턴스만 알고 있으면 모든 데이터에 접근 가능
* VO : 데이터마다 선별적 권한을 주거나(캡슐화), 인스턴스의 중앙관리(싱글톤)
* 데이터를 VO에 담고, VO를 CF에 담는 형태로 주로 사용
*
* 마셜링(mashaling) / 언마셜링(Unmashaling)
* - 전송할 수 있는 행태(다양한행태)로 개체 상태를 (변환)하는 프로세스
* - 바이트, JSON, XML
*/
// 중복 X, 순서보장 X
Set<Integer> set = new HashSet<Integer>();
set.add(1);
set.add(1);
set.add(1);
set.add(2);
set.add(3);
System.out.println(set.toString());
canSel();
// 중복 X, 순서보장 X
Map<String, String> map = new HashMap<>();
map.put("empno", 7733+"");
map.put("ename", "SMITH");
map.put("addr", "King");
//R
//String res3 = (String)map.get("ename");
String res3 = map.get("ename");
System.out.println(res3);
// U : 키값이 있으면 수정(값덮어쓰기), 신규키값이면 입력
map.put("addr" , "Seoul");
System.out.println(map.toString()); //{ename=king, empno=7733, addr=Seoul}
// D : 일치하는 키값이 있으면 삭제, 없으면. . 아무일도 없다.
map.remove("addr2");
System.out.println(map.toString());
//{ename=king, empno=7733, addr=Seoul}
map.forEach((key, value) -> System.out.println(key + " = " + value));
}
public static void canSel() {
System.out.println();
System.out.println("----------------------------");
}
}
'Kosta 클라우드 네이티브 어플리케이션 개발(CNA) 교육' 카테고리의 다른 글
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 18일차 (1) | 2024.12.11 |
---|---|
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 17일차 (0) | 2024.12.10 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 15일차 (1) | 2024.12.06 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 14일차 (1) | 2024.12.05 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 13일차 (1) | 2024.12.04 |