0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

kotlin count カウント

Posted at

Kotlin count

役割:要素の数を数える

使い方

count
A.count()
A.count{ it XXXX }
{}の中に条件式を記載

リストに対してカウント

count
  fun count(){
    val mojiList = listOf("a","b","c","a","a","e","p")
    println(mojiList.count())
    println(mojiList.count { it == "a" })
  }
result
7
3

数字に対してカウント

数字にはcountは使えないので、文字列に戻してから実行する必要がある

count
  fun count(){
    val suuji = 3173374856338339483
    println(suuji.toString().count())
    println(suuji.toString().count{ it == '3' })
  }
result
19
8
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?