阵列逻辑问题无法选择阵列中的项目

问题所在是

   else if ( salida[3].matches("[a-zA-Z]+") && !salida[3].equals("North") ) { // not working correctly
                    if (  !salida[3].equals("America")) {
                    salida1 = salida1 + salida[0] + " " + salida[1] + " " + salida[2] + " " + salida[3] +  ",";     

我有一个数组,下面的示例。我正在尝试检查第三个索引是否包含北或美国,如果没有,则应执行代码

salida1 = salida1 + salida[0] + " " + salida[1] + " " + salida[2] + " " + salida[3] +  ","; 

此代码允许将名称包含3个单词的国家/地区添加到字符串中

[United, States, 1,527,664, 90,978, North, America]
[Canada, 77,002, 5,782, North, America]

这是字符串输出

United States,Canada ,Mexico ,Dominican Republic,Panama ,Honduras ,Guatemala ,Cuba ,El Salvador,Costa Rica,Jamaica ,Haiti ,Martinique ,Guadeloupe ,Bermuda ,Trinidad and,Aruba ,Bahamas ,Cayman Islands,Barbados ,Sint Maarten,Saint Martin,Nicaragua ,Antigua and,Grenada ,Belize ,Saint Lucia,St. Vincent,Curaçao ,Dominica ,Saint Kitts,Turks and,Montserrat ,Greenland ,British Virgin,Saint Barthelemy,Caribbean Netherlands,Anguilla ,Saint Pierre,

输入国家/地区以显示数据:

public String setCountriesList() {
    String salida1 = "";
    try {
        Document doc = Jsoup.connect("https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/").get();
        Elements tr = doc.select("tr");
        String [] na = {"north", "america"};
        for (int i = 0; i < tr.size(); i++) {
            if (tr.get(i).text().contains("North America")) {
                String[] salida = tr.get(i).text().split(" ");  
                System.out.println(salida[3].contains("North") + " and " + salida[3].contains("America") );
                System.out.println(Arrays.deepToString(salida));                                                //split salida to country, number ,number in array
                if ( salida[1].matches("[a-zA-Z]+")) {
                    salida1 = salida1 + salida[0] + " " + salida[1] + ",";          
                }
                else if ( salida[2].matches("[a-zA-Z]+")) {
                    salida1 = salida1 + salida[0] + " " + salida[1] + " " + salida[2] +  ",";           
                }
                else if ( salida[3].matches("[a-zA-Z]+") && !salida[3].equals("North") ) { // not working correctly
                    if (  !salida[3].equals("America")) {
                    salida1 = salida1 + salida[0] + " " + salida[1] + " " + salida[2] + " " + salida[3] +  ",";             
                }}
         ```




                else {
                     salida1 = salida1 + salida[0] + " ,";
                }

            }
        }
        return salida1;
    } catch (Exception ex) {
        System.out.println("error");
        return "error";
    }
}
评论