I am having some trouble with a homework question:
Write a method f that accepts an ArrayList containing String objects.
The method should return a String cotaining the first character of each string in the ArrayList,
in the order in which thay appear. Thus, if the ArrayList contains the Strings:
Hello world goodbye
the return value of the method would be the String
Hwg
My formulated answer is:
public String f(ArrayList<String> list){
String text = "";
for(String s : list)
{
text += java.lang.String.charAt(0);
}
return text;
}
but I am getting the copiler error:
"CTest.java:8: non-static method charAt(int) cannot be referenced from a static context
text += java.lang.String.charAt(0);"
Which I don't know how to fix. Does anyone see what I am doing wrong?
Thanks : )
Edited by: Fredddir_Java on Jul 9, 2008 7:39 AM