What is the simplest SQL Query to find the second largest value?
SELECT MAX(col) FROM table WHERE col < (SELECT MAX(col) FROM table)
SELECT MAX(col) FROM table WHERE col NOT IN (SELECT MAX(col) FROM table);
What is the simplest SQL Query to find the second largest value?
SELECT MAX(col) FROM table WHERE col < (SELECT MAX(col) FROM table)
SELECT MAX(col) FROM table WHERE col NOT IN (SELECT MAX(col) FROM table);
length – arrays (int[], double[], String[]) —- to know the length of the arrays.
length() – String related Object (String, StringBuilder etc)to know the length of the String
size()– Collection Object (ArrayList, Set etc)to know the size of the Collection
length is not a method, so it completely makes sense that it will not work on objects. Its only works on arrays.
Points to Note
List An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
MapAn object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Test.java
public class Test { public static void main(String[] args) { List<String> arrNames = new ArrayList<String>(); arrNames.add("Hello"); arrNames.add(null); arrNames.add(null); arrNames.add("Hi"); System.out.println("List - "+arrNames.size()); Map hmTest = new HashMap(); hmTest.put("1", "mugil"); hmTest.put(null, null); hmTest.put(null, null); hmTest.put("1", "vannan"); System.out.println("HashMap - "+ hmTest.size()); Set<Integer> setTest = new HashSet<Integer>(); setTest.add(new Integer("10")); setTest.add(new Integer("20")); setTest.add(new Integer("10")); System.out.println("Set - "+ setTest.size()); } }
Output
List - 4 HashMap - 2 Set - 2