How to directly initialize a HashMap (in a literal way)?

All Versions In case you happen to need just a single entry: There is Collections.singletonMap(“key”, “value”). For Java Version 9 or higher: Yes, this is possible now. In Java 9 a couple of factory methods have been added that simplify the creation of maps : // this works for up to 10 elements: Map<String, String> … Read more

Initialization of an ArrayList in one line

It would be simpler if you were to just declare it as a List – does it have to be an ArrayList? List<String> places = Arrays.asList(“Buenos Aires”, “Córdoba”, “La Plata”); Or if you have only one element: List<String> places = Collections.singletonList(“Buenos Aires”); This would mean that places is immutable (trying to change it will cause … Read more

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