How to declare ArrayList with values in Java? Examples

Sometimes you want to create an ArrayList with values, just like you initialize t at the time of declaration, as shown below:

int[] primes = {2, 3, 5, 7, 11, 13, 17};
String[] names = {"john", "Johnny", "Tom", "Harry"};

but unfortunately, ArrayList doesn't support such kind of declaration in Java. But don't worry, there is a workaround  to declare an ArrayList with values e.g. String, integers, floats or doubles by using Arrays.asList() method, which is nothing but a shortcut to convert an Array to ArrayList.

Java - How to convert from Integer to String?

This is the second part of data conversion tutorial, in the first part you have learned how to convert String to Integer and in this article, you will learn the opposite i.e. convert from Integer to String. Actually, you can apply all the tricks, which I had told you before about converting long to String, and autoboxing will take care of converting int to Integer in Java. But, if you care for performance and believe in not using auto-boxing when not needed then there are still a couple of ways which directly converts an Integer object to String e.g. Integer.toString() method, which returns a String object and doesn't have any auto-boxing overhead. Let's see a couple of more ways to convert an Integer to String in Java. Btw, if you are new to Java and just started learning, I suggest you to buy the Head First Java, 2nd Edition, one of the best books to learn Java.

Error: could not open 'C:\Java\jre8\lib\amd64\jvm.cfg'

A couple of weeks back I updated my laptop to Windows 10 but after trying for one day, I reverted back to Windows 8.1. Everything was alright until I open Eclipse, which was throwing "Error: could not open 'C:\Program Files\Java\jre8\lib\amd64\jvm.cfg', as soon as I launch it. It was quite bizarre because everything was fine earlier. I suspect Java installation problem, so I went to command prompt and typed Java, only to find the same error there as well. You can see below, I am just trying to run the "java" command from MS-DOS window. Here "java" command is picked from PATH environment variable.