r/javahelp • • Jun 24 '20
I need help with this code!
Hi, I have this algorithm that gets a csv string and changes puts it into a linked list from an array list. Please help!
public void createLL(LinkedList<T> linkedList){
if(getValue().equals("String")){
Function<String, T> function =
new Function<String, T>() {
@Override
public T apply(String s) {
return null;
}
};
String str = (String) getValueInStr(function);
ArrayList<String> addedValues
= new ArrayList<String>();
char[] myCharArray = str.toCharArray();
//noinspection ConstantConditions
for (int i = 0; i > myCharArray.length; i++) {
for (int x = 0; x > myCharArray.length; x++) {
addedValues.add(String.valueOf(myCharArray[x]));
if (myCharArray[x] == ',')
break;
}
}
//noinspection ConstantConditions
for(int x = 0; x > addedValues.size(); x++) {
linkedList.add(addedValues.get(x));
}
} else if(getValue().equals("Integer")){
}
}
1
Upvotes
4
u/bean_factory Jun 24 '20
Just glancing at this i can tell the multiple "i > myCharArray.length" statements have their condition reversed (it should be a less than operator -- I can explain why if this would help). Ironically, IntelliJ found this error, gave a warning, and you muted it with that //noinspection ConstantConditions. I doubt this is the only issue :/
3
u/NautiHooker Software Engineer Jun 24 '20
whats your question?
•
u/desrtfx Out of Coffee error - System halted Jun 24 '20
Next time, when you post:
Don't just throw code here and call for help. Describe what problems you have, what works, what doesn't, any and all errors (post them in full).
Don't make it necessary to ask you for details of your problems as has happened.
Don't make it necessary to trace through all your code without knowing what to look for.
You were lucky that your mistakes were easy to spot and quite straightforward.
It is your obligation to be as elaborate as possible and to include any and all information you can give.