Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
1 つの数値を配列リスト全体と比較する if ステートメントを実行する方法はありますか? ユーザーに数字を入力してもらい、配列リストをスキャンして同じ数字を探し、配列リストから数字を出力したいと考えています。
使用できますcontains()。
contains()
Integer someInt = Integer.valueOf(10); if(list.contains(someInt)) { // other code }
Setここでは a の代わりに a を使用しListます。番号を追加しているため、おそらくリストに重複はありません。Set#contains()リストが巨大な場合は、はるかに優れたパフォーマンスを発揮します(ほぼ一定の時間)。
Set
List
Set#contains()