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?

More than 5 years have passed since last update.

Java基礎学習内容3(演算子・三項演算子)

Posted at

この記事は?

Javaを基礎から学習し直した際に、今まで理解不足だった点が多いと感じたため、後から見返せるよう学習内容をまとめたものです。

演算子

単項演算子・算術演算子など。計算や比較に用いる。

注意の必要な演算子

&と&& (|と||)

どちらもAND(OR)を示すが、&及び|は左辺がfalseの場合にも右辺が評価される。

instanceof

以下の形で用いる。(演算子だと知らなかったため念のため記載)

instanceof
str instanceof String;

==とequals()

基本データ型は==で比較可能だが、参照型の値を比較する場合はequals()を用いる。
(==で比較した場合、参照先が同一かどうかを比較することとなる。)

三項演算子

以下のように用いる。
?の前の条件式がtrueのときは左の式を、falseのときは右の式を実行する。

三項演算子
   String str = "a" == null ? "is null" : "is not null";
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?