How to stop the rest of code in current method from executing in Java? -


i have 4 textboxes, 2 of them being password boxes (for user confirm password).

here's code:

public void actionperformed(actionevent arg0) {     string username = usernamefield.gettext();     string emailaddress = emailfield.gettext();     string password1 = passwordfield1.gettext();     string password2 = passwordfield2.gettext();     if (password1 != password2) {         [code here]     } } 

how can make if passwords aren't equal stops rest of code in method executing?

there significant problem before can this: have compare strings correctly. then, can decide if they're false. ultimately, using return in void method acceptable if want return.

if (!password1.equals(password2)) {     // [code here] } 

however, better approach simple blanket check, , avoid early return - if passwords are valid, operations in scope of block. fall-through case exit method early.

public void actionperformed(actionevent arg0) {     string username = usernamefield.gettext();     string emailaddress = emailfield.gettext();     string password1 = passwordfield1.gettext();     string password2 = passwordfield2.gettext();     if (password1.equals(password2)) {         // code on success here     } } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -