JAVA/Common(5)
-
[JAVA] 압축 파일 생성 및 풀기
apache.commons.compress 받는곳 https://commons.apache.org/proper/commons-compress/download_compress.cgi import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; impo..
2018.05.03 -
ArrayList 정렬 및 자르기
1. ArrayList 정렬 Collections sort(students, new Comparator() { public int compare(Student s1,Student s2) { if(s1.getName() != null && s2.getName() != null && s1.getName().comareTo(s1.getName()) != 0) { return s1.getName().compareTo(s2.getName()); } else { return s1.getAge().compareTo(s2.getAge()); } } ); 2. ArrayList 자르기 List numbers = new ArrayList( Arrays.asList(5,3,1,2,9,5,0,7) ); List head = ..
2016.03.07 -
형 변환 모음...
Dealing with nulls UtilFactory.convertNull Java - comparing strings Use == for primitive data types like int If (mystring == null) Use the equals() method to compare objects Use .equals for strings : if (a.equals(“cat”)) Java - Converting int to string String myString = Integer.toString(my int value) or String str = "" + i Java - Converting String to int int i = Integer.parseInt(str); or int i =..
2015.05.28 -
인코딩 한방에 테스트 하기
public class Javatest{ public static void main(String args[]) { try{ String charSet[] = {"utf-8","euc-kr","8859_1"}; String fileName = "테스트"; for(int i = 0; i < charSet.length; i++) { for(int j = 0; j < charSet.length; j++) { System.out.println(charSet[i] + " to " + charSet[j] + " = " + new String(fileName.getBytes(charSet[i]),charSet[j])); } } }catch(Exception ex){ } } } [출처] java 인코딩 테스트를 한번에 ..
2015.04.23 -
String.format()을 이용하여 Date 표현하기
String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tI:%1$tS", new Date()); 결과 : 2013-10-01 15:15:20
2013.10.01