#My collections list wont print

30 messages · Page 1 of 1 (latest)

gusty swallow
#

i'm not sure why

heady oxideBOT
#

This post has been reserved for your question.

Hey @gusty swallow! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

gusty swallow
#

how do i post code

#

its too long

night quest
#

split it in two messages?

gusty swallow
#

isnt there a site

#

to format it all quickly

night quest
#

or only post the relevant parts

heady oxideBOT
#

Please format your code & make it more readable.
For the java programming language, it should look like this:

```java
public class Main{
public static void main(String[] args){
System.out.println("Hello World!");
}
}```
• These are backticks, not quotes.

gusty swallow
#
 public static void main(String[] args) throws FileNotFoundException {
        Scanner file = new Scanner(new File("/Users/michaelbalogun/Desktop/Lab11/src/main/java/applicant_data.csv"));
        ArrayList<candidate> applicants = new ArrayList<>();

        DecimalFormat round = new DecimalFormat("#.##");

        while (file.hasNextLine()) {
            String line = file.nextLine();
            String[] candidates = line.split(",");
            if (candidates.length >= 9) {
                try {

                    candidate c = new candidate(candidates[0], candidates[1], candidates[2], candidates[3], candidates[4], candidates[5], candidates[6], candidates[7],
                            Double.parseDouble(candidates[8]), candidates[9], candidates[10]);
                    applicants.add(c);
                } catch (NumberFormatException e) {
                }
            }

        }

        ArrayList<candidate> finalists = new ArrayList<>();
        for (candidate c : applicants) {
            String s1 = c.languages.toLowerCase();
            if (s1.contains("java")) {
                finalists.add(c);
            }
        }

        Collections.sort(finalists);
        System.out.println("The list of top 10 selected Java students are: ");
        for (int i = 0; i < Math.min(10, finalists.size()); i++) {
            System.out.println(finalists.get(i));
        }
    }
#

System.out.println(finalists.get(i));

#

wont print

night quest
#

Can you print finalists.size() before the loop?

#

Does that work?

#

Also

heady oxideBOT
gusty swallow
#

size is 0

#

not to sure why

#

i thoughti added to it

strange birch
#

Well it's better to check than to think

#

You should display information at all stages, was the split correct, are the fields where they're expected, is "java" there where expected...

#

Ideally with a debugger, but you can make do with whatever you know in the beginning

gusty swallow
#

trying to trace right now

#

after tracing thorugh

#

the error has to come from

gusty swallow
#

but i cant add to my finalists

#
 ArrayList<candidate> finalists = new ArrayList<>();
        for (candidate x : applicants) {
            String lang = x.languages.toLowerCase();
            if (lang.contains("java")) {
                finalists.add(x);
            }
        }

        Collections.sort(finalists);
        System.out.println(finalists.size());
        System.out.println("The list of top 10 selected Java students are: ");
        for (int i = 0; i < Math.min(10, finalists.size()); i++) {
            System.out.println(finalists.get(i));
        }
    }
night quest
#

maybe none of the languages contain java?