小编Abh*_*jee的帖子

如何检查arraylist是否包含字符串

我有这个代码,找到女性艺术家,男性艺术家或乐队的数量 -

 import java.util.*;


 public class FindGender {


    public static void main(String[] args) {
        // TODO code application logic here
        ArrayList < String > artists = new ArrayList < > ();
        int mnum = 0, fnum = 0, bnum = 0;
        artists.add("Beyonce (f)");
        artists.add("Drake (m)");
        artists.add("Madonna (f)");
        artists.add("Michael Jackson (m)");
        artists.add("Porcupine Tree (b)");
        artists.add("Opeth (b)");
        artists.add("FallOut Boy (b)");
        artists.add("Rick Ross {m}");
        artists.add("Chris Brown (m)");
        if (artists.contains("(b)")) bnum++;
        if (artists.contains("(m)")) mnum++;
        if (artists.contains("(f)")) fnum++;
        System.out.println("The number of male artists is: " …
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
3
解决办法
2019
查看次数

标签 统计

java ×1