java: How to write a generic type list [Note]

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 2020-10-12_15-05-52.png

Recommended Posts

java: How to write a generic type list [Note]
[Introduction to Java] How to write a Java program
How to write java comments
[Note] How to write Dockerfile/docker-compose.yml
Studying Java # 6 (How to write blocks)
How to make a Java container
[Java] How to create a folder
How to write a ternary operator
How to write Java variable declaration
[Java] How to use List [ArrayList]
How to make a Java array
How to use Java enum type
How to write a migration from Rails datetime type to date type
[Java] How to convert a character string from String type to byte type
How to sort a List using Comparator
How to make a Java calendar Summary
[Basic] How to write a Dockerfile Self-learning ②
[Java] How to add data to List (add, addAll)
[Java] How to output and write files!
How to make a Discord bot (Java)
How to print a Java Word document
How to use Java Scanner class (Note)
[SpringBoot] How to write a controller test
Rails: How to write a rake task nicely
[Rails] How to write when making a subquery
How to display a web page in Java
How to convert a solidity contract to a Java contract class
[Java] Memo on how to write the source
How to write Java String # getBytes in Kotlin?
[Java] How to operate List using Stream API
How to write Rails
How to write dockerfile
How to write docker-compose
How to write Mockito
How to write migrationfile
How to type backslash \
[Java] How to convert one element of a String type array to an Int type
How to create a Java environment in just 3 seconds
How to write Scala from the perspective of Java
[Java] Types of comments and how to write them
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
How to create a data URI (base64) in Java
[Java] How to get a request by HTTP communication
How to write a date comparison search in Rails
[Java] How to execute tasks on a regular basis
[Java] How to cut out a character string character by character
[Java] Things to note about type inference extended in Java 10
[Java] How to erase a specific character from a character string
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
How to write modern Java. Immutable Java, consider Null safety.
How to write a core mod in Minecraft Forge 1.15.2
[Java] How to start a new line with StringBuilder
I want to create a generic annotation for a type
How to save a file with the specified extension under the directory specified in Java to the list
A note about Java GC
[Java] How to use Map
[Java] List type / Array type conversion
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)