1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

今週の学びまとめ(Java / OOP / Bash / DD設計書)

Last updated at Posted at 2025-11-15

DD設計書の書き方のコツ

複雑な条件を表現する場合は デシジョンテーブル(Decision Table) を使用
図で表現すると条件が相手に伝わりやすい

API

Boolean.getBoolean()

引数に指定した システムプロパティの文字列が "true" の場合のみ true を返す

System.setProperty("flag", "true");
boolean b = Boolean.getBoolean("flag"); // true

Stream.filter().toList()

条件に一致する要素を抽出し、新しい List を作成

List<Integer> list1 = new ArrayList<>(List.of(1,2,3,4,5));
List<Integer> list2 = list1.stream()
                           .filter(v -> v != 3)
                           .toList(); // Java 16以上

LinkedHashMap と HashMap の違い

LinkedHashMap:順序保持のため双方向リストを内部に持つ。検索速度は HashMap とほぼ同じ
HashMap:順序非保持、挿入・削除は高速

map.putAll()

引数の Map の値を新しい Map にコピー

Map<String, String> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
map2.putAll(map1);

public static

static を付けると new せずクラス名で直接呼び出し可能

class BBB {
    public static void hello() {
        System.out.println("Hello");
    }
}
BBB.hello();

list.add と list.addAll の違い

add():単一要素を追加
addAll():別コレクションの要素をまとめて追加

参照型配列(String)の場合

String[] array = {"1","2","3","4","5"};
List<String> list = new ArrayList<>();
list.addAll(Arrays.asList(array)); // OK

プリミティブ型配列(int)の場合

int[] array = {1,2,3,4,5};
List<Integer> list = Arrays.stream(array)
                           .boxed()  // int → Integer
                           .collect(Collectors.toList());

ArrayUtils.nullToEmpty

引数が null の場合、空の List を返す

int[] array = null;
List<Integer> list = ArrayUtils.nullToEmpty(array);

Java 標準ではなく Apache Commons Lang のライブラリ機能

オブジェクト指向(OOP)

ポリモーフィズム

親クラス → 子クラスにメソッドを継承
子クラスで内容を変更することを オーバーライド
共通 DTO の設計に応用可能
親クラスに共通フィールド
子クラスに独自フィールド
DRY(重複排除)設計が可能

Java の動き

シャローコピー

構造だけコピー。中の要素は参照される
ミュータブルなオブジェクトの場合、元配列も変更される

int[] array1 = {1,2,3};
int[] array2 = array1.clone(); // シャローコピー

ディープコピー

新規配列を作成し、値だけコピー
元配列には影響しない

Bash

read -p {プロンプトメッセージ} {入力値}

read -p "名前を入力してください: " username
echo "こんにちは $username さん"

執筆者

Javaエンジニア。Hyrox挑戦中。
→ Qiita: @Katsu8998
https://hyrox-dashboard-kahbkakpyuagzybbm6buiz.streamlit.app/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?