How to get an enum value from a string value in Java

Yes, Blah.valueOf(“A”) will give you Blah.A. Note that the name must be an exact match, including case: Blah.valueOf(“a”) and Blah.valueOf(“A “) both throw an IllegalArgumentException. The static methods valueOf() and values() are created at compile time and do not appear in source code. They do appear in Javadoc, though; for example, Dialog.ModalityType shows both methods.

Print ArrayList

list.toString() is good enough. The interface List does not define a contract for toString(), but the AbstractCollection base class provides a useful implementation that ArrayList inherits.

What is a StringIndexOutOfBoundsException? How can I fix it?

Error Description Actual Reason Your code trying to create a substring with though your actual response string length is = 28, so String length is not long enough to create a substring of 500 characters. Solutions : Validate length using ternary operator ?:mTextView.setText(“Response is: “+ ((response.length()>499) ? response.substring(0,500) : “length is too short”)); Note : Ternary … Read more

Global variables in Java

To define Global Variable you can make use of static Keyword now you can access a and b from anywhere by calling

Java optional parameters

There are several ways to simulate optional parameters in Java: Method overloading.void foo(String a, Integer b) { //… }void foo(String a) { foo(a, 0); // here, 0 is a default value for b }foo(“a”, 2); foo(“a”); One of the limitations of this approach is that it doesn’t work if you have two optional parameters of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)