YJ의 새벽
JAVA (HashMap) 본문
--Map 인터페이스를 구현 ,
--데이터를 키와 값의 쌍으로 저장.
--순서 X 중복( 키x 값o )
--순서를유지하려면 LinkedHashMap
--TreeMap : TreeSet과 같은 특성, (키로 저장한다는 차이)
--Hashtable : 배열과 LinkedList 가 조합된 형태.
EX ))) HashMapExample ( 로그인 )
import java.util.HashMap;
import java.util.Scanner;
public class HashtableExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap map = new HashMap();
map.put("spring", "12");
map.put("summer", "123");
map.put("fall", "1234");
map.put("winter", "12345");
while(true) {
System.out.println("아이디와 비밀번호 입력하세요");
System.out.print("아이디 : ");
String id = scanner.nextLine().trim();
System.out.print("비밀번호: ");
String password = scanner.nextLine().trim();
System.out.println();
if(map.containsKey(id)) {
if(map.get(id).equals(password)) {
System.out.println("로그인");
break;
}else {
System.out.println("비밀번호다름");
}
}else {
System.out.println("아이디존재x");
}
}
}
}
'SelfStudy > JAVA' 카테고리의 다른 글
JAVA (제네릭) (0) | 2023.02.04 |
---|---|
JAVA (Collections), 컬렉션 요약정리. (0) | 2023.02.03 |
JAVA (HashSet, TreeSet) (0) | 2023.02.02 |
JAVA (Comparable , Comparator) (0) | 2023.02.02 |
JAVA (Iterator, Arrays) (0) | 2023.02.02 |
Comments