Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

If I have a method that creates an Array list, how do I call on a single value of that array?

For example;

public List<String> getWords() {
String[] List = words.split("[\\\w]+");
return Arrays.asList(list);
}

If getWords() returns [word1 word2 word3], How would I call upon say word1 (or list[0]) from outside the method?

1 Answer

Since you're using a List it would probably help to look and the List documentation: https://docs.oracle.com/javase/8/docs/api/java/util/List.html

String word1 = wordList.get(0);