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.
たとえば、List<String>「A」、「B」、「C」、「D」、「E」として保存されています。アイテム3の結果を取得したい場合= "C"。for-loop メソッドを使用せずにこれを行うにはどうすればよいですか?
List<String>
ループを使用する予定forだった場合、それは、リストのどのインデックスが「C」であるかを知らなかったからだと思います。その場合は、#indexOf(Object o)methodを使用できます。
for
#indexOf(Object o)
ArrayList<String> al = new ArrayList<String>(); al.add("a"); al.add("b"); al.add("c"); System.out.println(al.get(al.indexOf("b")));