My collections list wont print

i'm not sure why
14 Replies
JavaBot
JavaBotā€¢15mo ago
āŒ› This post has been reserved for your question.
Hey @Mike B! 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.
Mike B
Mike BOPā€¢15mo ago
how do i post code its too long
dan1st
dan1stā€¢15mo ago
split it in two messages?
Mike B
Mike BOPā€¢15mo ago
isnt there a site to format it all quickly
dan1st
dan1stā€¢15mo ago
or only post the relevant parts
JavaBot
JavaBotā€¢15mo ago
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.
Mike B
Mike BOPā€¢15mo ago
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));
}
}
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
dan1st
dan1stā€¢15mo ago
Can you print finalists.size() before the loop? Does that work? Also
JavaBot
JavaBotā€¢15mo ago
It looks like you are having issues with debugging or issues that can be solved using a debugger. Check out this article on dev.java to see how debugging works and how to use a debugger. This Stack Overflow question and its answers also explain debugging in general. These links describe how to use the debugger in some IDEs: ā€¢ Debugging in IntelliJ ā€¢ Debugging in Eclipse
Mike B
Mike BOPā€¢15mo ago
size is 0 not to sure why i thoughti added to it
Kyo-chan
Kyo-chanā€¢15mo ago
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
Mike B
Mike BOPā€¢15mo ago
trying to trace right now after tracing thorugh the error has to come from for soem reason my applicants gets added to 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));
}
}
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));
}
}
dan1st
dan1stā€¢15mo ago
maybe none of the languages contain java?
JavaBot
JavaBotā€¢15mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?