package com.google.sps.servlets;

import com.google.gson.Gson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** Returns map data as a JSON array, e.g. [{"lat": 38.4404675, "lng": -122.7144313}] */
@WebServlet("/map-data")
public class MapServlet extends HttpServlet {

    private class elementMap {
        double lat, lng;
        String name, description;

        public elementMap(double lat, double lng, String name, String description) {
            this.lat = lat;
            this.lng = lng;
            this.name = name;
            this.description = description;
        }
    }

    private ArrayList<elementMap> markers;

    @Override
    public void init() {
        markers = new ArrayList<elementMap>();

        Scanner scanner = new Scanner(getServletContext().getResourceAsStream("/WEB-INF/cities.csv"));
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            String[] cells = line.split(",");

            double lat = Double.parseDouble(cells[0]);
            double lng = Double.parseDouble(cells[1]);

            markers.add(new elementMap(lat, lng, cells[2], cells[3]));
        }
        scanner.close();
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/json");
        Gson gson = new Gson();
        String json = gson.toJson(markers);
        response.getWriter().println(json);
    }
}
@@ -108,24 +108,47 @@
 .ArrayList;%0A
+import java.util.List;%0A
 import java.
@@ -515,15 +515,22 @@
 ate 
+static 
 class 
-e
+E
 leme
@@ -612,17 +612,17 @@
  public 
-e
+E
 lementMa
@@ -841,27 +841,22 @@
 private 
-Array
 List%3C
-e
+E
 lementMa
@@ -866,16 +866,65 @@
 markers;
+%0A    private static final Gson GSON = new Gson();
 %0A%0A    @O
@@ -988,26 +988,16 @@
 rayList%3C
-elementMap
 %3E();%0A%0A  
@@ -1002,16 +1002,20 @@
         
+try(
 Scanner 
@@ -1099,17 +1099,19 @@
 s.csv%22))
-;
+) %7B
 %0A       
@@ -1111,16 +1111,20 @@
         
+    
 while (s
@@ -1143,24 +1143,28 @@
 xtLine()) %7B%0A
+    
             
@@ -1205,24 +1205,28 @@
             
+    
 String%5B%5D cel
@@ -1252,32 +1252,36 @@
 );%0A%0A            
+   
+ 
 double lat = Dou
@@ -1307,16 +1307,20 @@
 ls%5B0%5D);%0A
+    
         
@@ -1375,24 +1375,28 @@
             
+   
+ 
 markers.add(
@@ -1399,17 +1399,17 @@
 add(new 
-e
+E
 lementMa
@@ -1442,16 +1442,20 @@
 s%5B3%5D));%0A
+    
         
@@ -1464,16 +1464,20 @@
         
+    
 scanner.
@@ -1481,24 +1481,34 @@
 er.close();%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -1674,84 +1674,8 @@
 %22);%0A
-        Gson gson = new Gson();%0A        String json = gson.toJson(markers);%0A
     
@@ -1707,20 +1707,36 @@
 println(
-json
+GSON.toJson(markers)
 );%0A    %7D

Add the suggestions regarding the MapServlet.