Quantcast
Channel: OKWAVE 閲覧数の多い質問(Java/253)【本日】
Viewing all articles
Browse latest Browse all 68675

booleanの意味・・・

$
0
0
お世話になります。 javaの勉強をし始めたばかりなのですが booleanの理解がなかなか出来なくて困っています。 例えば、 public ArrayList search(ArrayList blist, String word) { boolean hit = false; ArrayList setList = new ArrayList(); for (int i=0; i<blist.size(); i++) { Parson bean = (Parson) blist.get(i); int n =bean.getName().indexOf(word); if (n != -1) { setList.add(bean); hit = true; } } if (! hit) { System.out.println("その文字では検索できません!"); } return setList; } というプログラムで、booleanを使っていてif (n != -1)のブロックに 入った時は、hit=tureで下のif (! hit)の処理を行うのは分かるのですが…。 もし、if (n != -1)のブロック内に入らなければhitはfalseのままでは ないのでしょうか? falseのまま、if (! hit)のブロックにきたらhitはtrueになるので 処理は行われないのでは?と思うのですが…。 この辺の理解ができなくて、教えて頂きたく思います。 宜しくお願いします。

Viewing all articles
Browse latest Browse all 68675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>