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

Spring Bootをさわっててよく出てくるメソッドまとめ

Posted at

まずこちらをご覧いただこう

       var test = Optional.ofNullable(status())
                .map(Hi -> Hi.stream()
                        .map(内緒の中身)
                        .toList())
                .orElse(List.of());

これはOptionalのstatusから値を取り出すとき

        var hasUserManageAuth = user.getAuthorities().stream()
                .allMatch(authority -> authority.getAuthority()
                        .equals(AuthorityKind.ADMIN.getRoles()));

引用:https://youtu.be/FscpHmaiTEw?si=fYpr0mgUOlWUnLMS
  (この方のこのシリーズおすすめです)
細かいところがないとわからないかもだけど、これはADMIN権限があるかチェックしてる

.equalsだの.allMatchだの(変数1 -> 変数1)だのややこしいんじゃあああ!!
わかるかあああああああああああああ!!!!!!!!!!!!
いちいち調べるものだるいわああああああああああ!!!!!!!!!

ということで、私がSpringを学んだ時に出てきたメソッドをまとめました。
つまり、タグにもある通り完全なる自己中備忘録です。

目次

.orElse
.stream
.equals

結果的に何が値に入るのか

多分、文の最後で判断できる
.equalsならtrueかfalse
.orElseならその中身

orElse

メソッドの引数がnullの場合にorElseメソッドの引数の値を返す。

System.out.println(変数1.orElse("Nullだよ"));

この場合、Nullだよが入る

stream

APIの一種で、配列などの集合体において値の集計やデータを使った処理などが出来る便利なやつ
.streamのあとにメソッドが続くから理解するまでに時間かかる。
ここらへんで詰まるのはだいたいコイツのせい、嫌い

a.stream().toList

とかつなげて利用される

equals

String型用の比較。int型における==と同じ意味。
Stringで==を使うと参照先が同じかを比較することになるからequalsを使う
==ならtrue、!=はfalseを返す


以降出てきたら更新します

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?