Tag Archives: foreach

ForEach loop object required error

Questions: Summary: I have a list of policy numbers I’m looping through in Column A using the for each loop Problem: Everything works except if there is an empty cell in Column A, my code deletes the entire row (as it should), but then when I try to set the policy variable I get a… Read More »

Deleting rows in a foreach

Questions: I’m trying to update a sheet with an import of a .CSV file.. I can read and update all the information. After the update I want to remove some data. All the rows with D empty must be deleted (whole row). For that, I have a foreach that checks D3:D486 (is last row). After… Read More »

SQL Server: sp_MSforeachdb into single result set

Questions: I am going to archive to get a query which pulls some data from all databases and return a single result set. Right now I have the following: DECLARE @command varchar(4000) SELECT @command = ‘ USE [?] SELECT database_name = DB_NAME(database_id) , log_size_mb = CAST(SUM(CASE WHEN type_desc = “LOG” THEN size END) * 8.… Read More »

Break or return from Java 8 stream forEach?

Questions: When using external iteration over an Iterable we use break or return from enhanced for-each loop as: for (SomeObject obj : someObjects) { if (some_condition_met) { break; // or return obj } } How can we break or return using the internal iteration in a Java 8 lambda expression like: someObjects.forEach(obj -> { //what… Read More »

Use <c:forEach> with HashMap [duplicate]

Questions: This question already has an answer here: How to loop through a HashMap in JSP? 2 answers Answers: Yes, this is perfectly acceptable. When you use <c:forEach> to iterate over a Map, each item in the iteration is an instance of Map.Entry. So given your example: <c:forEach var=”type” items=”${types}”> Key is ${type.key} Value is… Read More »

What is difference between Collection.stream().forEach() and Collection.forEach()?

Questions: I understand that with .stream(), I can use chain operations like .filter() or use parallel stream. But what is difference between them if I need to execute small operations (for example, printing the elements of the list)? collection.stream().forEach(System.out::println); collection.forEach(System.out::println); Answers: For simple cases such as the one illustrated, they are mostly the same. However,… Read More »