「Java」Integer型、String型、Double型リストの値を取得するサンプル

2021年1月5日

書式
public static <T> List<T> asList(T… a)
指定された配列に連動する固定サイズのリストを返します。返されたリストへの変更は、そのまま配列に書き込まれます。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CalendarDemo {
//int型配列
protected static Integer cftA[] = { 11, 22, 33, 44 };
//string型配列
protected static String cftB[] = { "TA01", "TB02", "TC03", "DD04" };
//double型配列
protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 };
public static void main(String[] args) {
List<Integer> lstA = new ArrayList<>(Arrays.asList(cftA));
List<String> lstB = new ArrayList<>(Arrays.asList(cftB));
List<Double> lstC = new ArrayList<>(Arrays.asList(cftC));
// Integer型リストの要素を取得
System.out.println("Integer型リストの要素下記");
for (int n : lstA) {
System.out.println(n);
}
// String型リストの要素を取得
System.out.println("string型リストの要素下記");
for (String m : lstB) {
System.out.println(m);
}
// Double型リストの要素を取得
System.out.println("Double型リストの要素下記");
for (Double d : lstC) {
System.out.println(d);
}
}
}
package com.arkgame.study; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CalendarDemo { //int型配列 protected static Integer cftA[] = { 11, 22, 33, 44 }; //string型配列 protected static String cftB[] = { "TA01", "TB02", "TC03", "DD04" }; //double型配列 protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 }; public static void main(String[] args) { List<Integer> lstA = new ArrayList<>(Arrays.asList(cftA)); List<String> lstB = new ArrayList<>(Arrays.asList(cftB)); List<Double> lstC = new ArrayList<>(Arrays.asList(cftC)); // Integer型リストの要素を取得 System.out.println("Integer型リストの要素下記"); for (int n : lstA) { System.out.println(n); } // String型リストの要素を取得 System.out.println("string型リストの要素下記"); for (String m : lstB) { System.out.println(m); } // Double型リストの要素を取得 System.out.println("Double型リストの要素下記"); for (Double d : lstC) { System.out.println(d); } } }
package com.arkgame.study;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CalendarDemo {

      //int型配列
      protected static Integer cftA[] = { 11, 22, 33, 44 };
      //string型配列
      protected static String cftB[] = { "TA01", "TB02", "TC03", "DD04" };

      //double型配列
      protected static Double cftC[] = { 12.34, 21.35, 35.21, 68.12 };

      public static void main(String[] args) {

            List<Integer> lstA = new ArrayList<>(Arrays.asList(cftA));
            List<String> lstB = new ArrayList<>(Arrays.asList(cftB));
            List<Double> lstC = new ArrayList<>(Arrays.asList(cftC));

            // Integer型リストの要素を取得
            System.out.println("Integer型リストの要素下記");
            for (int n : lstA) {
                  System.out.println(n);
            }

            // String型リストの要素を取得
            System.out.println("string型リストの要素下記");
            for (String m : lstB) {
                  System.out.println(m);
            }

            // Double型リストの要素を取得
            System.out.println("Double型リストの要素下記");
            for (Double d : lstC) {
                  System.out.println(d);
            }

      }

}

実行結果
Integer型リストの要素下記
11
22
33
44
string型リストの要素下記
TA01
TB02
TC03
DD04
Double型リストの要素下記
12.34
21.35
35.21
68.12

Java

Posted by arkgame