java: The merit of generic type is that the type is specified. It also shortens the code.
demojava/demo14/Demo14.java
package demojava.demo14;
import java.util.ArrayList;
import java.util.List;
public class Demo14 {
public static void main(String[] args) {
List<String> L = new ArrayList<String>();
String hoge = "Hello List";
char[] C = hoge.toCharArray();
for (int i = 0 ;i < C.length; i++){
L.add(String.valueOf(C[i]));
}
for (String val : L) {
System.out.println(val);
}
}
}
Execution result
Recommended Posts