LoginSignup
0
0

More than 1 year has passed since last update.

Pairクラスを使う

Posted at

たまに思っていたこと

「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.getLight(); // "to"

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

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

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