2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pairクラスを使う

Last updated at Posted at 2023-04-17

たまに思っていたこと

「1メソッドから戻り値が2つ(以上)ある時ってどう返せばいいんだ?」

例えば開始時間と終了時間が欲しいんだけどどうreturnに詰め込めばいいのか

Map使うとか、setter/getterクラス作るとかやってましたがapacheが入ってる場合はPairクラスってのがあるそうで

import org.apache.commons.lang3.tuple.Pair;

Pair<String, String> pa = Pair.of("from", "to");
pa.getLeft(); // "from"
pa.getRight(); // "to"

ちなみに3つならTripleというのもあります

便利ですねえ…しかしJavaUtilに加えてapacheだのフレームワークだの便利グッズが多すぎてなかなか覚えきれない

2
0
1

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?