본문 바로가기

반응형

JAVA/JAVA

자바 컬렉션 프레임워크에 대한 설명 순서1. 컬렉션 프레임워크 사용 이유2. 컬렉션 프레임워크 종류3. 컬렉션 프레임워크 종류에 대한 설명4. 컬렉션 프레임워크의 장단점5. ArrayList 와 LinkedList 의 다른 동작방식6. List 와 Map 의 사용방식에 따른 쓰임새 1. 왜 컬렉션 프레임워크(Set, List, Map)을 사용해야 할까요?전통적으로 프로그래밍에서 많은 양의 자료(데이터)처리를 위해서는 배열을 이용한다.그러나 이 배열은 불편한 점이 2가지가 있다. 1. 배열에 담는 자료형은 동일해야 한다. 밑에 문장처럼 배열에 한가지 자료형밖에 담을 수 있다.한가지뿐 아니라 다른 자료형도 함께 넣고 싶지만 그냥 배열에서는 힘든 부분이다.int []arr = new int[100]; 2. 배열은 데이터의 크기를 알 수 없는 경.. 더보기
자바 Wrapper class 관련 설명 및 예제 Wrapper class=> 기본자료형을 객체로 포장하기 위한 클래스들서로 다른 자료형끼리의 형변환을 위해 사용문자열 데이터 => int문자열 데이터 => floatint => 문자열float => 문자열... 기본자료형 => 클래스들boolean => Booleanchar => Characterbyte => Byteshort => Shortint => Integerlong => Longfloat => Floatdouble => Double class WrapperTest02 {public static void main(String[] args) {String str1 = "29";String str2 = "31.9"; //두개의 문자열의 값을 각각 int,double 변환한 다음 더하기 연산후 결과를 .. 더보기
자바 날짜와 시간 관련 클래스 - 종류 및 예제 날짜와 시간을 가지고 있는 클래스(date 보단 calendar 를 쓰라고 권장함) -Date -Calendar밑에 예제처럼 date처럼 new를 사용하면 에러가 난다. new를 이용해 직접 객체를 생성할 수 없다메소드 중에 calendar를 생성해서 주는게 있음 -GregorianCalendar윤년에 대한 파악을 할 수 있는 클래스Calendar보다 쓰기 쉽도록 new를 이용해 만들 수 있다.(Calendar에 윤년에 대한 개념 추가된것) -System.currentTimeMillis1970년 1월 1일 이후부터 현재 까지의 시간을 밀리세컨으로 반환사용용도1) 날짜 처리2) 특정작업을 수행하는데 걸린 시간3) 난수발생 Date 클래스는 일요일 ==> 0 부터 시작Calendar 클래스는 일요일 ==> .. 더보기
자바 예제 - Calendar : Calendar 를 이용한 월,일,시,분,초 그리고 요일 알아내기 import java.util.Calendar; class CalendarTest{ public static void main(String[] args) { Calendar today = Calendar.getInstance(); int year = today.get(Calendar.YEAR);int month = today.get(Calendar.MONTH+1);int date = today.get(Calendar.DATE);int day = today.get(Calendar.DAY_OF_WEEK);int hour = today.get(Calendar.HOUR);int minute = today.get(Calendar.MINUTE);int second = today.get(Calendar.SECOND).. 더보기
자바 예제 - Date : Date 을 이용한 월,일,시,분,초 그리고 요일 알아내기 날짜 Date 이용 1. 기본예제2. 월,일,시,분,초 그리고 요일 알아내기(switch 이용)3. 월,일,시,분,초 그리고 요일 알아내기(배열 이용) //날짜처리와 관련한 클래스import java.util.Date; class DateTest01{public static void main(String[] args) {Date today = new Date();System.out.println(today); //Date클래스의 toString()이 호출됨}} : Switch 문 사용한것 //날짜처리와 관련한 클래스import java.util.Date; class DateTest01{public static void main(String[] args) {Date today = new Date();Sys.. 더보기
자바 예제 - StringTokenizer : 문자열의 각 단어의 빈도수를 구하여 출력하는 프로그램을 작성(String.split) import java.util.StringTokenizer; class StringTest06{public static void main(String[] args){String str = "hello hello hello java hello jsp hello orcale hello java";String arr[] = new String[100]; //[hello] [java] [] [] [][]...[]int cnt[] = new int[100]; //[3] [1] [] [] []..[]int n=0;//중복되지 않는다면 n번째 데이터를 넣고 n을 증가시키고자 한다. int j=0;String []st = str.split(" ");//[hello][hello][hello][java][hello][]... 더보기
자바 예제 - StringTokenizer : 문자열에서 각 단어의 빈도수를 구하는 프로그램 작성 import java.util.StringTokenizer; class StringTokenizerTest {public static void main(String[] args) {String names = "사용자1,사용자2,사용자3,사용자4,사용자5";StringTokenizer st = new StringTokenizer(names, ","); while (st.hasMoreTokens()){System.out.println(st.nextToken());}}} import java.util.StringTokenizer; class StringTest05 {public static void main(String[] args) {String str = "hello korea hello java hell.. 더보기
자바 StringTokenizer에 대하여 StringTokenizer: 데이터가 스페이스가 있는 경우 분리를 해준다.Token : 한단어단어를 얘기하는듯함hasMoreToken : 더 토큰이 있나 물어보고 없으면 while문 탈출nexToken : 다음 단어로 넘어가는 의미 이것은 lang에 없으므로 import java.util.StringTokenizer; 를 사용해야함 The following is one example of the use of the tokenizer. The code:StringTokenizer st = new StringTokenizer("this is a test");while (st.hasMoreTokens()) {System.out.println(st.nextToken());} prints the followin.. 더보기

반응형