Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Arraylist question.

807589Jul 9 2008 — edited Jul 9 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2008
Added on Jul 9 2008
10 comments
1,625 views