본문 바로가기
프로그래밍/Flutter & Dart

[Flutter/dart] List class

by 소꿍 2021. 8. 15.

List<E> class

List는 length와 인덱스 접근이 가능한 콜렉션

 

Dart의 List class(https://api.dart.dev/stable/2.13.4/dart-core/List-class.html) 에서 필요한 부분을 정리했다.

 

 

서브클래스로 Fixed-length list와 Growable list가 있는데,

말 그대로 Fixed-length list는 길이가 고정된 list이고, Growable list는 아이템에 따라 길이가 조정된다.

 

Fixed-length list는 List의 길이를 변경하려고 하면 에러가 발생한다.

default는 Growable list이다.

 

  • List.length - List의 길이 (아래 methods와 달리 property여서 () 없이 사용)

  • List.indexOf(E element, [int start = 0]) - element가 있는 index를 리턴

  • List.add(E value) - List의 마지막에 value를 추가

  • List.insert(int index, E element) - List[index]에 element 삽입
  • List.contains(Object? element) - element의 포함 여부를 리턴

  • List.clear() - List의 모든 object를 삭제

참고한 문서

댓글