본문 바로가기

Common 34

HashSet을 사용한 클래스 중복 제외 Student Classpublic class Student { private String name; private int age; public Student(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } //================================================= //추가 HashSet에 키로 사용할 필드를 Override 한다. @Override public int hashCode() { return name.hashCode(); } @Override public boole.. 2015. 3. 14.
String format 사용법 String sValue = " 홍길동"; int nValue = 123; long lValue = 123L; float fValue = 123.4567F; double dValue = 123.4567; //%s는 문자열 출력에 사용되는 기호이다. System.out.println(String.format("%s 입니다.", sValue)); 홍길동 입니다. //%d는 정수형 출력에 사용되는 기호이다. //%다음에 숫자가 오면 그 숫자만큼의 자리수가 확보된다. //%0다음에 숫자가 오면 빈 공백이 0으로 채워진다. System.out.println(String.format("%d", nValue)); System.out.println(String.format("%5d", nValue)); System.o.. 2014. 12. 18.
한글 Encoding 문제 해결 String id= new String(session.getAttribute("id").toString().getBytes("ISO-8859-1"), "UTF-8"); JSP 2014. 12. 10.
String.Split에서 \r\n 처리 방법 String.Split에서 Enter Key(\r\n)은 다음과 같이 처리하면 된다. 1. string[] lines = doc.Split('\n'); for (int i = 0; i < lines.Length; i+= 1) lines[i] = lines[i].Trim(); 2. *예제.txt에는 \r\n이 포함된 문자열이 있다고 가정 string path = "예제.txt"; string content = File.ReadAllText(path); string[] lines = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); 2014. 5. 30.