프로그래밍/자바 6

Java - JSONObject에서 element와 accumulate 차이점

두 개다 name(key)와 value로 데이터를 넣어주는 형식이다. 사용 방식은 같으나 accumulate는 같은 key가 들어왔을 때 배열 식으로 계속해서 value를 붙여주는 형식을 띄고 element는 같은 key가 들어왔을 때 value를 이전 value에 덮여씌워 주는 형식이다. ex) 소스: JSONdata data1 = new JSONdata("data1"); JSONdata data2 = new JSONdata("data2"); JSONdata data3 = new JSONdata("data3"); JSONdata data4 = new JSONdata("data4"); //값 추가 jsonByDTO.accumulate("ticketIDList", data1); jsonByDTO.accum..

Java - StringBuilder 사용하기

StringBuilder는 StringBuffer와 같은 역활을 합니다. 차이점은 StringBuilder는 스레디 세이프하지 않기 때문에 단일 스레드 환경에서만 사용을 해야 합니다. 대신 StringBuffer보다는 좀 더 빠른 성능을 보여 줍니다. public static void main(String[] args) { StringBuilder sb = new StringBuilder(); sb.append(true); System.out.println(sb); sb.append('a'); System.out.println(sb); char[] chars = new char[] { 'd', 'e', 'f' }; sb.append(chars); System.out.println(sb); int i = ..

[Java] WeakReference 와 SoftReference 의 차이점.

안녕하세요 돼지왕 왕돼지입니다 오늘은 Weak Reference 와 Soft Reference 에 대해 알아보았습니다. WeakReference. Object 를 참조하는 형태 세 가지 중의 하나입니다. GC 가 발생할 때 어떤 object 가 weakly-reachable 이라면 다음과 같은 일이 발생합니다. 1. Weakly-reachable object "를" 참조하는 모든 reference 를 모은다. 2. Weakly-reachable object "가" 참조하는 모든 reference 를 모은다. ( 참조형태는 strong 이든 weak 이든 상관없다. ) 3. 1, 2 를 통해 모은 모든 reference 를 한번에 다 해제한다. 4. reference 가 해제된 object 들은 final..

[java] WeakReference 와 SoftReference

각각에 개념부터. WeakReference 말그대로, '약한' 참조 이다. '약한' 참조는 해당 객체에 대한 소멸을 막지 않는다. 즉, 어떤 객체에 대한 참조가 WeakReference 밖에 남아있지 않다면 그 객체는 gc(Garbage Collection) 의 대상이 된다. 펼치기 - J2SE 5.0 api 문서의 설명 원문 Weak reference objects, which do not prevent their referents from being made finalizable, finalized, and then reclaimed. Weak references are most often used to implement canonicalizing mappings. Suppose that the ga..

Enumeration 클래스와 ListIterator 클래스

ListIterator는 Iterator를 상속받아서 기능을 추가한 것, 양방향으로 이동이 가능. ArrayList나 LinkedList와 같이 List 인터페이스를 구현한 컬렉션만 사용가능. Enumeration는 Iterator의 구버젼격. 예제 첫번째 package kch; import java.util.ArrayList; import java.util.ListIterator; public class ListIteratorEx1 { public static void main(String[] args){ ArrayList list = new ArrayList();//리스트를 선언하고 list.add("1"); list.add("2"); list.add("3"); list.add("4"); list.a..

반응형