자바 Vector와 ArrayList에 관한 간단한 질문입니다. 답변해 주세요 ㅜㅜ
맑은
import java.util.*;
class listex02 {
public static void main(string[] args) {
/*
* arraylist와 vector의 선언
*/
liststring strarraylist = new arrayliststring(5);
liststring strvector = new vectorstring(5, 5);
/*
* list에 요소 추가하기
*/
strarraylist.add(홍길동);
strvector.add(홍길동);
/*
* list의 크기 구하기
*/
system.out.println(strarraylist.size());
system.out.println(strvector.size());
// vector의 메모리 할당량
system.out.println(
((vectorstring)strvector).capacity());
/*
* collections.addall() 이용한 추가
*/
collections.addall(strarraylist, 이몽룡, 성춘향,
월매, 변악도, 향단이, 방자);
collections.addall(strvector, 이몽룡, 성춘향,
월매, 변악도, 이몽룡, 향단이, 방자);
/*
* index를 이용한 요소 읽어오기
*/
system.out.println(
((arrayliststring)strarraylist).get(2));
system.out.println(
((vectorstring)strvector).elementat(2));
// vector에서 첫번째 요소 읽기
system.out.println(
((vectorstring)strvector).firstelement());
system.out.println(
((vectorstring)strvector).indexof(이몽룡));
// vector에서 마지막 요소 읽기
system.out.println(
((vectorstring)strvector).lastelement());
system.out.println(
((vector)strvector).lastindexof(이몽룡));
// arraylist와 vector에 포함된 요소의 개수 알아내기
system.out.println(searchcount(strarraylist, 이몽룡));
system.out.println(searchcount(strvector, 이몽룡));
}
public static int searchcount(collectionstring c, string s) {
iteratorstring i = c.iterator();
int count = 0;
while (i.hasnext()) {
if (i.next().equals(s)) count++;
}
return count;
}
}
다음은 벡터와 arraylist에 관한 것입니다.
system.out.println( ((vectorstring)strvector).elementat(2)); 가 이해가 안되네요.
((vectorstring)strvector).elementat(2)); -여기만 이해가 안갑니다.
캐스트를 할때 vectorstring 요런식으로 캐스트를 하나요? 처음보는 거여서 .
자세히 설명 부탁드립니다 ㅜㅜ
그 부분만 자세하게 설명해주시면 될것 같아요 ㅜㅜ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2702487 | 저작권관련 긴급질문요~ (6) | 지희 | 2025-07-23 |
2702459 | 최근 포트폴리오 부분 질문드려요 | 흰가람 | 2025-07-23 |
2702431 | 플래시9에서 lite는 얼마나 발전할까요? (6) | 자올 | 2025-07-23 |
2702375 | mvc패턴 게시판 ..........아힘들어요 고수님들좀상세히도와주세요;; (3) | 냐하 | 2025-07-22 |
2702317 | ie6메뉴 보더문제 (3) | VanilLa | 2025-07-22 |
2702287 | c++ 변수 중간값 뽑아내서 비교하는 법 | 헛장사 | 2025-07-21 |
2702258 | AS2,0 함수에서 매개변수의 타입이 각각 다를때는? (5) | 하림 | 2025-07-21 |
2702228 | 이 표현은 무엇인지... 몰라서요. (2) | 도란도란 | 2025-07-21 |
2702197 | dll 인젝션 사용법좀 알려주세요 | 새밝 | 2025-07-21 |
2702147 | dd 안에 div들어가도 되나요? (8) | 꿈 | 2025-07-20 |
2702086 | [질문]세션 박스 질문입니다. (1) | 하연 | 2025-07-20 |
2702057 | 씨언어 숙재좀 풀어주실분 ㅜ.ㅜ (3) | 난슬 | 2025-07-19 |
2702000 | select 사용시 label 문제 질문드립니다. | 김예쁨 | 2025-07-19 |
2701970 | 실행파일의 이름은 어디서 변경하는지요???? | 호빵녀 | 2025-07-19 |
2701856 | 다시 한번 대체텍스트 관련 질문입니다.. (1) | 한샘가온 | 2025-07-18 |
2701803 | 저에게 지식의 자비를~ 베푸소서~!! (4) | 봄바람 | 2025-07-17 |
2701773 | 메모장 파일을 읽고 출력하는 내용에 관한 질문입니다. | 한국드립 | 2025-07-17 |
2701748 | 아이피 변경 부분이요... | 날애 | 2025-07-17 |
2701665 | 자바스크립트 // 왜 if 두개를 쓰면 오류가 나죠? (2) | 글리슨 | 2025-07-16 |
2701636 | 모바일웹 게시판 만들기 조언좀 부탁드려요 ㅜㅜ (2) | 정훈 | 2025-07-16 |