Number of elements in a javascript object

Although JS implementations might keep track of such a value internally, there’s no standard way to get it. In the past, Mozilla’s Javascript variant exposed the non-standard __count__, but it has been removed with version 1.8.5. For cross-browser scripting you’re stuck with explicitly iterating over the properties and checking hasOwnProperty(): function countProperties(obj) { var count … Read more

Converting String array to java.util.List

List<String> strings = Arrays.asList(new String[]{“one”, “two”, “three”}); This is a list view of the array, the list is partly unmodifiable, you can’t add or delete elements. But the time complexity is O(1). If you want a modifiable a List: List<String> strings = new ArrayList<String>(Arrays.asList(new String[]{“one”, “two”, “three”})); This will copy all elements from the source … Read more

Why can Java Collections not directly store Primitives types?

It was a Java design decision, and one that some consider a mistake. Containers want Objects and primitives don’t derive from Object. This is one place that .NET designers learned from the JVM and implemented value types and generics such that boxing is eliminated in many cases. In CLR, generic containers can store value types … Read more

How to sort a HashSet?

A HashSet does not guarantee any order of its elements. If you need this guarantee, consider using a TreeSet to hold your elements. However if you just need your elements sorted for this one occurrence, then just temporarily create a List and sort that: Set<?> yourHashSet = new HashSet<>(); … List<?> sortedList = new ArrayList<>(yourHashSet); … Read more

Are there strongly-typed collections in Objective-C?

In Xcode 7, Apple has introduced ‘Lightweight Generics’ to Objective-C. In Objective-C, they will generate compiler warnings if there is a type mismatch. NSArray<NSString*>* arr = @[@”str”]; NSString* string = [arr objectAtIndex:0]; NSNumber* number = [arr objectAtIndex:0]; // Warning: Incompatible pointer types initializing ‘NSNumber *’ with an expression of type ‘NSString *’ And in Swift … Read more

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