본문 바로가기

Engineering/JAVA4

[펌]about String, StringBuilder, StringBuffer 원문 : http://blog.naver.com/windziel?Redirect=Log&logNo=60048694876 자바에서 스트링을 연결하여 사용할때 String str = "aaa" + "bbb" + "ccc"; 의 형태로 사용하면 안된다고 알고 있었다. String은 불변(Immutable) 객체이기 때문에 '+'를 이용하여 문자열을 연결하게 되면 각 ""안의 String를 생성하고 이후 블록이 끝난후 GC의 대상이 되기 때문이다. 그래서 String을 연결할 때는 StringBuffer, StringBuilder 객체를 생성하고 append 메소드를 사용하여 연결한 후 StringBuffer, StringBuilder의 toString() 메소드로 스트링을 생성한 후 사용하여야 한다고 알고 있.. 2008. 6. 2.
Java에서 Pattern, Matcher로 원하는 것만 뽑아내기. /** * XML파일을 파싱해서 이미지 파일 목록만 뽑아낸다. * @param XMLFilePath * @return 이미지 파일 목록이 들어있는 ArrayList */ private ArrayList extractImgSrc(String XMLFilePath) { BufferedReader reader; StringBuffer sb = new StringBuffer(); char[] buf = new char[512]; ArrayList imgTagList = new ArrayList(); ArrayList imgSrc = new ArrayList(); Pattern pattern; Matcher matches; try { reader = new BufferedReader(new FileReader(X.. 2008. 2. 23.
Thread 종료시키기. 이렇게 해도 되는 것인지 모르겠다. -_-public class RecvThread implements Runnable { public void run() { try { byte[] reqCode = new byte[1]; while (!Thread.currentThread().isInterrupted()) { is.read(reqCode); switch (reqCode[0]) { case Protocol.RESPONSE_LOGIN: loginHandler(); break; case Protocol.RESPONSE_SLOGIN: sLoginHandler(); break; case Protocol.RESPONSE_JOIN: joinHandler(); break; case Protocol.RESPONSE_D.. 2008. 2. 4.
Stopping thread in Java 졸작을 하다가 네트워크 프로그래밍에서 쓰레드를 닫으려고 쓰레드의 stop()을 호출했는데, 이클립스에서 deprecated라는 경고가 떴다. 왜그런가 해서 뒤져봤더니 흠냐 -_- Java Thread Primitive Deprecation Why is Thread.stop deprecated? Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagates up the stack.) If any of the objects previously protected .. 2008. 2. 4.