Quantcast
Channel: DaniWeb Solved Topics
Viewing all articles
Browse latest Browse all 582

Error returning a boolean from method

$
0
0

Hi guys,
I seem to have an issue with a boolean method returining a value. Here is the code excerpt - irrelevant code omitted:

public class StreamsTest {

    public static void main(String[] args) {
        String[] arr = new String[]{"a", "b", "c"};         
        //convert array to string with streams
        List<String> list = Arrays.stream(arr).collect(Collectors.toList());        
        isElementInIt(list);   
    }

    static boolean isElementInIt(List<String> list) {
        if(list.isEmpty()) {
            return false;
        }
        else {
            for (String string : list) {
                if (string.contains("a")) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }       
    }
}

STS says that the isElementInIt method should return a boolean value, but it's already doing that whatever happens, so I'm not too sure why the error. Any idea?
thanks


Viewing all articles
Browse latest Browse all 582

Latest Images

Trending Articles



Latest Images