Java BasicMap
์ ์ ๋ฐฉ๋ฒ: Map
Map student = new HashMap<>();
์ธ ๊ฐ์ ๊ตฌ์ฑ ์์๋ก
Entry
Method: EntrySet(), KeySet(), Values()๋ ๊ฐ๋ณ ์ปฌ๋ ์ ์ ๋ฐํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
public class MapTest {
private Map student;
//initiate Student in constructor
public MapTest(){
student = new HashMap<>();
}
public void testKeyset(){
// Set
Set kSet;
kSet = student.keySet();
//Set Key ๏ผ String
for(String stID: kSet){
System.out.println("Student:" + stID);
}
}
public void testEntryset(){
// Entry
Set> eSet = student.entrySet();
for(Entry e:eSet){
System.out.print("ID is: " + e.getKey());
System.out.println("Name is: " + e.getValue().getName());
}
}
์ฆ๊ฐ, ์ญ์ , ๋ณ๊ฒฝ, ์กฐ์ฌ:put() ์ฆ๊ฐ, ์ฆ๊ฐ ๊ณผ์ ์์ get() ๋ฐฉ๋ฒ๊ณผ ํจ๊ป ๊ฐ์ ๋์์ด ์๋ ์งํฉ์ ์ด๋ฏธ ์กด์ฌํ๋์ง ํ์ธ:student.get (ID) ์ ๋งต ํ์ ์งํฉ์ ์๋ก์ด ์์๋ก ๋ค์ด๊ฐ๋ ํ๋จ ์กฐ๊ฑด์ ๋๋ค. ๋งต ์๋์ Set ํด๋์ค๋ ๊ฐ์ ์์๊ฐ ์์ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
public void testPut(){
Scanner console = new Scanner(System.in);
String ID;
Student st;
Student newStudent;
String name;
int i=0;
while(i<3){
System.out.println("Input student ID: ");
ID = console.next();
st = student.get(ID);
// get ๏ผ value.
if(st == null){
System.out.println("Input student name: ");
name = console.next();
newStudent = new Student(ID, name);
// put ๏ผ get
student.put(ID, newStudent);
System.out.println("Student added: " + student.get(ID).getName());
System.out.println();
i++;
}
//
else{
System.out.println("The ID's been taken");
continue;
}
}
์ญ์ ๋remove๋ฅผ ์ฌ์ฉํ๊ณ get()์ ์ฌ์ฉํ์ฌ ๋ฏธ๋ฆฌ ํ๋จํฉ๋๋ค
public void testRemove(){
Scanner console = new Scanner(System.in);
String ID;
Student st;
Student newStudent;
String name;
while(true){
System.out.println("Input the name to be removed: ");
ID = console.next();
st = student.get(ID);
if(st==null) {
System.out.println("The input ID doesn't exist!" );
continue;
}
else{
student.remove(ID);
break;
}
}
}
์๊ธฐ 2๋ก์์ ์ํ์ ์ฌ์ฉ์ ๋์์ ์ฃผ์ํด์ผ ํ๋ค. ๋ง์ฝ์ ์ํํ๋ ๊ณผ์ ์์ ์กฐ๊ฑด ํ๋จ ํ์ ์งํ์ด ์ํ ๊ณ์์ ์ํ ์ ์ด์ ์ํฅ์ ์ค ์ ์์ผ๋ฉดwhile๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค.foreach๋ณด๋ค ์ข ๋ ์ ์ฐํ๋ค.
int i=0;
while(i<3){
if(...){
...
i++;
}
else{
}
elsei
๋ํ:
while(true){
if(... ){ ...
continue;
}
else{...
break;
}
์ํ์ ๋ํ ์ ์ด: ์ฌ์ํ +while (true) + continue, ๊ทธ๋ฆฌ๊ณ ์ํ ์ข ๊ฒฐ:break.๊ฐ์ฅ ์ข์while ์ํ์ ์ฌ์ฉํฉ๋๋ค.
๋ณ๊ฒฝ, ์ฌ์ ํput์ ์ฌ์ฉํ์ฌ ๊ฐ์ ID๋ฅผ ์ ๋ ฅํ๊ณ ์ง์ ์์
String name = scanner.next();
st = new Student(ID, name);
student.put(ID, st);
์ด ๋ด์ฉ์ ํฅ๋ฏธ๊ฐ ์์ต๋๊น?
ํ์ฌ ๊ธฐ์ฌ๊ฐ ์ฌ๋ฌ๋ถ์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ง ๋ชปํ๋ ๊ฒฝ์ฐ AI ์์ง์ ๋จธ์ ๋ฌ๋ ๋ถ์(์ค๋งํธ ๋ชจ๋ธ์ด ๋ฐฉ๊ธ ๋ง๋ค์ด์ ธ ๋ถ์ ํํ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์)์ ํตํด ๊ฐ์ฅ ์ ์ฌํ ๊ธฐ์ฌ๋ฅผ ์ถ์ฒํฉ๋๋ค:
๋ค์ํ ์ธ์ด์ JSONJSON์ Javascript ํ๊ธฐ๋ฒ์ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ๋ ์ด์์ํ๋ ๋ฐ์ดํฐ ํ์์ ๋๋ค. ๊ทธ๋ฌ๋ Javascript๊ฐ ์ฝ๋์์ ์ด๋ฌํ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ผ ์ ์๋ ์ ์ผํ ์ธ์ด๋ ์๋๋๋ค. ์ ๋ ์ผ๋ฐ์ ์ผ๋ก '๊ฐ์ฒด'{}...
ํ ์คํธ๋ฅผ ์์ ๋กญ๊ฒ ๊ณต์ ํ๊ฑฐ๋ ๋ณต์ฌํ ์ ์์ต๋๋ค.ํ์ง๋ง ์ด ๋ฌธ์์ URL์ ์ฐธ์กฐ URL๋ก ๋จ๊ฒจ ๋์ญ์์ค.
CC BY-SA 2.5, CC BY-SA 3.0 ๋ฐ CC BY-SA 4.0์ ๋ฐ๋ผ ๋ผ์ด์ผ์ค๊ฐ ๋ถ์ฌ๋ฉ๋๋ค.
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค