main문
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Main {
public static void main(String[] args) {
new sol1().run();
new sol2().run();
}
}
class user{
private String name;
private int age;
private double height;
public user(String name, int age, double height){
this.name = name;
this.age = age;
this.height = height;
}
@Override
public String toString() {
return "user{" +
"name='" + name + '\'' +
", age=" + age +
", height=" + height +
'}';
}
}
방법1 > class 구성
class sol1{
public void run(){
user u1 = new user("사람1",12,132.2);
System.out.println(u1);
}
}
방법2 > map 구성
class sol2{
public void run(){
Map<String, Object> u1 =new HashMap<>();
u1.put("나이",12);
u1.put("이름","사랍1");
u1.put("키",132.2);
Map<String, Object> u2 =new HashMap<>(){{
put("나이",12);
put("이름","사랍1");
put("키",132.2);
}};
System.out.println(u1);
System.out.println(u2);
int 나이 = (Integer) u1.get("나이");
String 이름 = (String) u1.get("이름");
double 키 = (Double) u1.get("키");
System.out.printf("name=%s, age=%d, height=%.1f",이름,나이,키);
}
}