메뉴 건너뛰기

조회 수 1281 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

package kr.din102.library;

public class Convert
{


 /**
  * 문자열을 int 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static int toInt(String strTarget)
 {
  int retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Integer.parseInt(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 short 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static short toShort(String strTarget)
 {
  short retValue = (short) 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   Short.parseShort(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 long타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static long toLong(String strTarget)
 {
  long retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Long.parseLong(strTarget);
  return retValue;
 }

 

 /**
  * 문자열을 double 타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return 0 또는 숫자
  */
 public static double toDouble(String strTarget)
 {
  double retValue = 0;

  strTarget = strTarget.trim();
  if (!strTarget.equals(""))
   retValue = Double.parseDouble(strTarget);
  return retValue;
 }

 

 /**
  * 숫자형을 부울타입으로 반환
  *
  * @param nTarget 변환하고자 하는 숫자타입
  * @return 1 이상일 경우 true, 0이하일 경우 false;
  */
 public static boolean toBoolean(int nTarget)
 {
  boolean retValue = false;

  if (nTarget > 0)
   retValue = true;
  else
   retValue = false;
  return retValue;
 }

 

 /**
  * 문자열을 부울타입으로 반환
  *
  * @param strTarget 변환하고자 하는 문자열
  * @return  문자열이 1 이상 또는 true 일경우 true,
  *       문자열이 0 이하 또는 false 일 경우 false
  */
 public static boolean toBoolean(String strTarget)
 {
  boolean retValue = false;

  if (strTarget == null || strTarget.trim().equals(""))
  {
   retValue = false;
  }
  else
  {
   strTarget = strTarget.trim().toLowerCase();

   if (strTarget.equals("true") || strTarget.equals("1"))
    retValue = false;
   else
    retValue = true;
  }
  return retValue;
 }

 

 /**
  * 구분자로 구성된 문자열을 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static String[] toStringArray(String strTarget, String strDelimiter)
 {
  if (strTarget == null || strTarget.trim().length() == 0 || strDelimiter == null || strTarget.equals(""))
  {
   return null;
  }

  return strTarget.split(strDelimiter);
 }

 

 /**
  * List 인터페이스형의 리스트를 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static String[] toStringArray(java.util.List objList)
 {
  if (objList == null)
   return null;

  String[] retValue = (String[]) objList.toArray();

  return retValue;
 }

 

 /**
  * 구분자로 구성된 int 타입 배열로 변환하기
  *
  * @param strTarget 구분자로 구성된 문자열
  * @param strDelimiter 구분자
  * @return 구분자로 구분된 배열
  */
 public static int[] toIntegerArray(String strTarget, String strDelimiter)
 {
  String[] arrStrArray = toStringArray(strTarget, strDelimiter);
  int nCntList = arrStrArray.length;
  int[] arrIntArray = new int[nCntList];

  for (int i = 0; i < nCntList; i++)
  {
   arrIntArray[i] = Integer.parseInt(arrStrArray[i]);
  }
  return arrIntArray;
 }

 

 /**
  * 8859_1 -> KSC5601 로 변환하기
  *
  * @param strTarget 8859_1 문자열
  * @return KSC5601 문자열
  * @throws Exception
  */
 public static String toKorean(String strTarget) throws Exception
 {
  if (strTarget == null)
   return "";

  return new String(strTarget.getBytes("8859_1"), "KSC5601");
 }

 

 /**
  * KSC5601 -> 8859_1 로 변환하기
  *
  * @param strTarget KSC5601 문자열
  * @return 8859_1 문자열
  * @throws Exception
  */
 public static String toEnglish(String strTarget) throws Exception
 {
  if (strTarget == null)
   return "";

  return new String(strTarget.getBytes("KSC5601"), "8859_1");
 }

} // 끝 - Class Convert



List of Articles
번호 제목 날짜 조회 수
71 enum 2016.09.13 3404
70 문자 기반 스트림 2016.09.13 3440
69 쓰레드의 우선순위 2016.09.13 3503
68 파일I/O 개요 file 2016.09.13 3507
67 Jadclipse 플러그인 설치 file 2016.09.19 3512
66 인터페이스와 다형성 2016.09.13 3535
65 File 클래스 file 2016.09.13 3603
64 원하는 패턴의 날짜 구하기 : JAVA 2016.12.09 3608
63 새로 만든 모듈의 iBatis 쿼리를 새로운 xml 파일에 만들고 싶다면 이렇게 하자. file 2016.08.29 3651
62 set get 파라미터 2016.08.18 3658
61 컬렉션 프레임워크 file 2016.09.13 3705
60 JAR 파일 2016.09.19 3713
59 BigDecimal타입의 사칙연산 2016.12.22 3713
58 클래스 메서드와 인스턴스 메서드 2016.09.13 3720
57 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동]3. 이클립스 설치 file 2016.08.18 3756
56 바이트 기반의 스트림 file 2016.09.13 3763
55 static멤버와 관련된 예제 2016.09.21 3768
54 새로 만든 모듈의 iBatis 쿼리를 새로운 xml 파일에 만들고 싶다면 이렇게 하자. file 2016.08.29 3773
53 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서07.commons-collection 설치 file 2016.08.18 3845
52 Select statements cannot be executed as an update. 에러 해결방법 file 2016.08.29 3848
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved