0

So, while looking through others code ive been seeing things like such as in the following code:

List myList = new ArrayList<String>(Arrays.asList(s.split(" ")));

What exactly does this do? I haven't been able to find any documentation, in part by the reason that I don't really know what it is called. And if possible an explanation of what exactly they do?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
sirnomnomz
  • 623
  • 1
  • 7
  • 20

2 Answers2

1

That particular code generates a list that contains the entries resulted from splitting the s string at each space.

The < String> defines the generic type for the List, and the advantage (among other ones) is that you can call myList.get(index) and not have to cast it to a String.

Gabriel Ruiu
  • 2,753
  • 2
  • 19
  • 23
0

This is a generic. You are instantiating an ArrayList that stores String objects.

Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94