본문 바로가기

IT/JAVA

java 한글 byte로 깨짐없이 자르기 public String subStringBytes(String str, int byteLength, int sizePerLetter) { int retLength = 0; int tempSize = 0; int asc; if (str == null || "".equals(str) || "null".equals(str)) { str = ""; } int length = str.length(); for (int i = 1; i 127) { if (byteLength >= tempSize + sizePerLetter) { tempSize += sizePerLetter; retLength++; } } else { if (byteLength > tempSize) { tempSize++; retLength++; .. 더보기
URL에서 정보 가져오기 import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL("http://example.com:80/docs/books/tutorial" + "/index.html?name=networking#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); //http System.out.println("authority = " + aURL.getAuthority()); //example.com:80 System.out.println("host = " + a.. 더보기
HashMap 정렬 HashMap key순서로 정렬하기. import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.TreeMap; public class MapSort { public static void main(String[] args){ HashMap hashMap = new HashMap(); hashMap.put("test3", "name5"); hashMap.put("test4", "name2"); hashMap.put("test5", "name1"); hashMap.put("test1", "name3"); hashMap.put("test2", "name4"); System.out.println(".. 더보기
JAVA 특수문자 split lf (data.contains("+")) String tmp[] = data.split("+") 에러내용 : Dangling meta character '+' near index 0split("+")부분에서 컴파일러가 + 부분을 인식 못함.해결: String tmp[] = data.split("[+]")로 변경.아니면 특수문자 앞에 \\쓸것. (예 data.split("\\+"))String연산 함수(예:replaceAll()..) 이용시 주의할것. 참고 http://blog.naver.com/kim22922/80097490823자바의 특수문자와 그 기능 \n u000A new line \t u0009 tab \r u000D return \f u000C form feed \\ u005C backsals.. 더보기
랜덤숫자 7개 생성하기 (로또번호 생성하기,정렬) public class lotto { public static void main(String[] args) {int temp;int no[]={0,0,0,0,0,0};int bonus=0;for(int i=0;i 더보기