如何将二维数组直接添加到hashmap?

时间:2016-04-23 14:10:46

标签: java arrays generics int

而不是:

int[][] someArr = { { 88, 35 }, { 11, 98 } };
mapDE = new HashMap<String, int[][]>();
mapDE.put("someKey", someArr);

我想这样做是为了保存一行代码:

mapDE = new HashMap<String, int[][]>();
mapDE.put("someKey", { { 88, 35 }, { 11, 98 } });

这么简单吗?

3 个答案:

答案 0 :(得分:1)

mapDE.put("someKey", { { 88, 35 }, { 11, 98 } });无法编译,因为{ { 88, 35 }, { 11, 98 } }无法确保类型int[][]

您可以尝试这种方式:

    Map<String, int[][]> mapDE = new HashMap<String, int[][]>();
    mapDE.put("someKey",new int[][] { { 88, 35 }, { 11, 98 } });

答案 1 :(得分:1)

使用此:

leafletProxy("bosmap", data = hubway) %>%
  clearShapes() %>% clearMarkers %>% clearPopups() %>%

  for(i in 1:26){

    addPolygons(data = subset(neighborhoods, neighborhoods$Name %in% c(toString(neighborhoods$Name[i]))),
                stroke = FALSE, 
                color = "red",
                smoothFactor = 0.5,
                fillOpacity = 0.3,
                popup = toString(neighborhoods$Name[i])) %>%

  }

  addPopups(longMark, latMark, poppy,
            options = popupOptions(closeButton = FALSE)
  ) %>% ...(and so on)

答案 2 :(得分:1)

你非常接近,请尝试以下方法:

public class MainCollector {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Document doc;
        try {
            doc = Jsoup.connect("http://aldogroup.luceosolutions.com/recruit/stores/advert_details.php?id=3136&_lang=en&partner_id=139").get();
            String title = doc.title();
            String body = doc.body().toString();
            Document convertText = Jsoup.parseBodyFragment(body);
            String convertedText = convertText.text();
            System.out.println("Title:" + title);
            System.out.println("Body:" + convertedText);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}