Re: help with ArrayLists !
Does your code compile? If not, please copy and paste the full text of the error messages here.
Re: help with ArrayLists !
Code:
arrayListPractice.java:115: error: incompatible types
String named = longest.get(i);
^
required: String
found: Object
arrayListPractice.java:117: error: array required, but String found
if(named[i].length > max){
^
arrayListPractice.java:117: error: cannot find symbol
if(named[i].length > max){
^
symbol: variable max
location: class arrayListPractice
arrayListPractice.java:119: error: longest is already defined in findLongestName(ArrayList<String>)
int longest;
^
arrayListPractice.java:128: error: cannot find symbol
return names( longest);
^
symbol: method names(ArrayList)
location: class arrayListPractice
arrayListPractice.java:142: error: incompatible types
String named = shortest.get(i);
^
required: String
found: Object
arrayListPractice.java:144: error: array required, but String found
if(named[i].length < min){
^
arrayListPractice.java:146: error: shortest is already defined in findShortestName(ArrayList<String>)
int shortest;
^
arrayListPractice.java:155: error: cannot find symbol
return names( shortest);
^
symbol: method names(ArrayList)
location: class arrayListPractice
arrayListPractice.java:163: error: size has private access in ArrayList
for ( int i = names.size; i > 0; i -- ){
^
arrayListPractice.java:167: error: method eliminate in class arrayListPractice cannot be applied to given types;
if(eliminate(i) == "Harrison" || eliminate(i) == "John" || eliminate(i) == "Dilpreet" || eliminate(i) == "Arman"){
^
required: ArrayList<String>
found: int
reason: actual argument int cannot be converted to ArrayList<String> by method invocation conversion
arrayListPractice.java:167: error: method eliminate in class arrayListPractice cannot be applied to given types;
if(eliminate(i) == "Harrison" || eliminate(i) == "John" || eliminate(i) == "Dilpreet" || eliminate(i) == "Arman"){
^
required: ArrayList<String>
found: int
reason: actual argument int cannot be converted to ArrayList<String> by method invocation conversion
arrayListPractice.java:167: error: method eliminate in class arrayListPractice cannot be applied to given types;
if(eliminate(i) == "Harrison" || eliminate(i) == "John" || eliminate(i) == "Dilpreet" || eliminate(i) == "Arman"){
^
required: ArrayList<String>
found: int
reason: actual argument int cannot be converted to ArrayList<String> by method invocation conversion
arrayListPractice.java:167: error: method eliminate in class arrayListPractice cannot be applied to given types;
if(eliminate(i) == "Harrison" || eliminate(i) == "John" || eliminate(i) == "Dilpreet" || eliminate(i) == "Arman"){
^
required: ArrayList<String>
found: int
reason: actual argument int cannot be converted to ArrayList<String> by method invocation conversion
arrayListPractice.java:175: error: cannot find symbol
return eliminate ;
^
symbol: variable eliminate
location: class arrayListPractice
Note: arrayListPractice.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
15 errors
Re: help with ArrayLists !
Which of the error messages are you having trouble with? Most are self explanatory. For example:
array required, but String found
The compiler has found a variable in a statement that is a String but by the syntax of the statement the variable type should be an array.
A technque to keep from getting so many errors at once is to type in the minimum code and do a compile, fix the errors and compile again. Continue until you get a clean compile. Then add a few more lines and do it again.
Don't wait until you have typed in 170+ lines before trying to compile your program.