Инструменты пользователя

Инструменты сайта


works:programmer:java:array-empty-test

Тесты с ArrayList

import java.lang.String;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
 
public class HelloWorld {
 
    public class RwTest {
        public String name;
        public String value;
        public RwTest(String name, String value) {
            this.name = name;
            this.value = value;
        }
        public String toString() {
            return String.format("{\"type\": \"RwTest\",\"%s\": \"%s\"}", name, value);
        }
    }
 
    private List<RwTest> testList;
 
    public List<RwTest> getTestList() {
        return testList == null ? Collections.emptyList() : testList;
    }
 
    public HelloWorld() {
        this.testList = new ArrayList<>();
        this.testList.add(new RwTest("test1", "Hello, World!"));
        this.testList.add(new RwTest("test1", "Hello, EugeneX!"));
    }
 
    public void run() {
        var t = getTestList();
        System.out.println(t);
    }
 
    public static void main(String[] args) {
        (new HelloWorld()).run();
    }
 
}
works/programmer/java/array-empty-test.txt · Последнее изменение: 2021/08/12 08:02 — 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki