Check a collection size with JSTL
How can I check the size of a collection with JSTL? Something like: <c:if test=”${companies.size() > 0}”> </c:if> 4 Answers 4
How can I check the size of a collection with JSTL? Something like: <c:if test=”${companies.size() > 0}”> </c:if> 4 Answers 4
I’m sure there’s a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can’t find an elegant way of retrieving a single item from it. If I know I want the first item, … Read more
This question already has answers here: Is there an IDictionary implementation that, on missing key, returns the default value instead of throwing? (18 answers) Closed 9 years ago. I find myself using the current pattern quite often in my code nowadays var dictionary = new Dictionary<type, IList<othertype>>(); // Add stuff to dictionary var somethingElse = … Read more
I’ve got a generic dictionary Dictionary<string, T> that I would like to essentially make a Clone() of ..any suggestions. 14 Answers 14
Say I have 3 strings in a List (e.g. “1”,”2″,”3″). Then I want to reorder them to place “2” in position 1 (e.g. “2”,”1″,”3″). I am using this code (setting indexToMoveTo to 1): listInstance.Remove(itemToMove); listInstance.Insert(indexToMoveTo, itemToMove); This seems to work, but I am occasionally getting strange results; sometimes the order is incorrect or items from … Read more
I have two arraylist filelist and imgList which related to each other, e.g. “H1.txt” related to “e1.jpg”. How to automatically randomized the list of imgList according to the randomization of fileList? Like in excel, if we sort certain column, the other column will automatically follow? String [] file = {“H1.txt”,”H2.txt”,”H3.txt”,”M4.txt”,”M5.txt”,”M6.txt”}; ArrayList<String> fileList = new ArrayList<String>(Arrays.asList(file)); … Read more
DataGridView, for example, lets you do this: DataGridView dgv = …; DataGridViewCell cell = dgv[1,5]; but for the life of me I can’t find the documentation on the index/square-bracket operator. What do they call it? Where is it implemented? Can it throw? How can I do the same thing in my own classes? ETA: Thanks … Read more
I’m migrating a piece of code to make use of generics. One argument for doing so is that the for loop is much cleaner than keeping track of indexes, or using an explicit iterator. In about half the cases, the list (an ArrayList) is being iterated in reverse order by using an index today. Can … Read more
In practice, is it better to return an empty list like this: return Collections.emptyList(); Or like this: return new ArrayList<Foo>(); Or is this completely dependent upon what you’re going to do with the returned list? 7 Answers 7
I want to verify whether a collection is empty and null. Could anyone please let me know the best practice. Currently, I am checking as below: if (null == sampleMap || sampleMap.isEmpty()) { // do something } else { // do something else } 9 Answers 9