In my day to day web application development there are many instances where we need to take some number inputs from the user.
Then pass on this number input to may be service or DAO layer of the application.
At some stage since its a number (integer or float), we need to convert it into Integer as shown in the following code snippet.
String cost = request.getParameter("cost");
if (cost !=null && !"".equals(cost) ){
Integer intCost = Integer.parseInt(cost);
List<Book> books = bookService . findBooksCheaperThan(intCost);
}
Here in the above case I have to check if the input is not null or if there is no input (blank) or sometimes there is a possibility of a non number inputs e.g. blah, test etc.
What is the best possible way of handling such situations?
if (cost !=null && !"".equals(cost) )
===if (!"".equals(cost))
;) – Fabulous