일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 생활코딩
- 대덕인재개발원
- FastAPI
- Homebrew
- spring
- 이클립스
- pyqt
- ddit
- 맥
- python
- 객체지향
- nodejs
- servlet
- 자바
- Error
- ibatis
- JDBC
- jsp
- 배열
- Android
- Oracle
- Java
- crud
- 단축키
- 컬렉션프레임워크
- API
- Mac
- 자바문제
- 반복문
- html
Archives
- Today
- Total
romworld
Properties 본문
package kr.or.ddit.basic;
import java.util.Properties;
public class PropertiesTest {
/*
properties객체
- Properties객체는 Map보다 축소된 기능의 객체라고 할 수 있다.
- Map은 Key값과 value값에 모든 형태의 객체를 사용할 수 있지만
Properties객체는 Key값과 value값에 String만 사용할 수 있다.
- Map은 put(), get()메서드를 이용해서 데이터를 저장하고 읽고하는 작업을 수행하지만
Properties는 setProperty(), getProperty() 메서드를 이용해서 읽고 쓰기 작업을 수행한다.
- Properties객체는 데이터를 파일로 입출력 할 수 있다.
*/
public static void main(String[] args) {
// 객체 생성
Properties prop = new Properties();
prop.setProperty("name", "홍길동");
prop.setProperty("age", "20");
int num = 30;
//prop.setProperty("num", num + ""); // num + "" int를 string으로 바꾸는 거
prop.setProperty("num", String.valueOf(num)); //String.valueOf() 문자열로 바꿔주는 거
prop.setProperty("tel", "010-124-5678");
prop.setProperty("addr", "대전");
//-----------------------------------------------------------------------------
String name = prop.getProperty("name");
int age = Integer.parseInt(prop.getProperty("age")); //문자열을 정수형으로 바꾸는거
int num2 = Integer.parseInt(prop.getProperty("num"));
String tel = prop.getProperty("tel");
String addr = prop.getProperty("addr");
//Float fff = Float.parseFloat("3.14f"); // 플롯은 이렇게 변환 시키고..
//double fff1 =Double.parseDouble("3.14f"); // 더블은 이렇게...
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
System.out.println("번호 : " + num);
System.out.println("전화 : " + tel);
System.out.println("주소 : " + addr);
}
}
Comments