I was trying to create a function to expand the brackets in a linear equation. Unfortunately, I couldn't get the function to function, and I have been getting errors. Below is the code I wrote:
List openBracket(List<String> equationComponents) {
List eqtComponents = [];
for (int i = 0; i < equationComponents.length; i ) {
if (containsBracket(equationComponents.get(i))) {
eqtComponents.addAll((equationComponents.get(i)));
} else {
eqtComponents.add(equationComponents.get(i));
}
}
return eqtComponents;
}
This is the error that I am facing:
"The method 'get' isn't defined for the type 'List'. Try correcting the name to the name of an existing method, or defining a method named 'get'."
I can't seem to solve the problem.
I have searched on YouTube and Google but found no solutions to the problem. I Have been trying to find alternatives to the ".get" method but to no avail.
CodePudding user response:
You can use myList.elementAt(x)
or just myList[x]
for list.
equationComponents.elementAt(x)
List openBracket(List<String> equationComponents) {
List eqtComponents = [];
for (int i = 0; i < equationComponents.length; i ) {
if (containsBracket(equationComponents.elementAt(i))) {
eqtComponents.addAll([equationComponents[i]]); // add all need list
} else {
eqtComponents.add(equationComponents.elementAt(i));
}
}
return eqtComponents;
}
More about List