defined variable:
LinkedList list1=new LinkedList();
Object get() in list1 obtains a node of list1
Object remove() in list1 deletes a node of list1
count() is length of list1
for(int i=1;i<list1.count();i++){
if(list1.get(i).startsWith('"',0)) //Error here
list1.remove(i);
}
Error: cannot find symbol
symbol: method charAt(int)
location: class Object
how to fix this problem?
I would like to delete the node in list1 which starts with (“).
startsWithis a method in theStringclass; you are using the raw LinkedList type, and thus it is treated like aLinkedList<Object>. If you wish to use Strings, make it aLinkedList<String>.startsWithaccepts onlyStringarguments, notchararguments. UsestartsWith("\"")instead.startsWithis superfluous; providing no second parameter will assume starting position as 0.ifstatement. This will cause theifbody to be treated as empty. Definitely remove this semicolon and optionally use curly braces.Your modified solution may look something like this:
Additional notes:
For example: