如何在JAVA中用新值替换ArrayList(具有多个列)中的值

时间:2016-07-29 21:39:16

标签: java arraylist multiple-columns

当ArrayList是单列时,我已阅读很多关于更新ArrayList中某个值的帖子。在我的例子中,我有一个多列ArrayList,它通过使用以下JAVA代码完成。

select  
((FLOOR(end_date - start_date))*24)
|| '.' ||
ROUND(
       (
         (
           ((end_date - start_date)-(FLOOR(end_date - start_date)))*24
         ) - 
         FLOOR((((end_date - start_date)-(FLOOR(end_date - start_date)))*24))
       )*60
    )
from 
come_leav;   

然后我的ArrayList看起来像,     {0.0,1.0}     {2.0,5.0}     {3.0,8.0}

我的问题是:我尝试用新号码替换号码8.0。而且我认为我不能使用“ArrayList.set(2,8.0)”来实现这个目标,因为它只在ArrayList有一个列时才能正常工作。

欢迎任何反馈和评论。

4 个答案:

答案 0 :(得分:1)

  

您应首先从arrayList中选择数组。

library(dplyr)
do.call(rbind, lapply(df, function(col) { 
    t.result = t.test(col); 
    data.frame(SUM = sum(col), SD = sd(col), 
               CIL = t.result$conf.int[1], CIH = t.result$conf.int[2]) })) %>% 
    add_rownames(var = "CAT") %>% arrange(desc(SUM))

# Source: local data frame [4 x 5]

#     CAT   SUM        SD        CIL      CIH
#   <chr> <int>     <dbl>      <dbl>    <dbl>
# 1  cook     5 0.9831921 -0.1984635 1.865130
# 2 youth     4 0.8164966 -0.1901939 1.523527
# 3 child     3 1.2247449 -0.7852909 1.785291
# 4  doit     1 0.4082483 -0.2617636 0.595097

答案 1 :(得分:0)

您需要致电.get()以获取您正在寻找的阵列。

然后,您可以在数组中设置单个值。

答案 2 :(得分:0)

这里是一个单行班,将8.0的值更改为4.4

Dim sUrl As String
Dim Xmlhttp As New MSXML2.ServerXMLHTTP60

strJSONToSend = "[{""FieldCode"": ""AccountHolderFirstName"",""FieldValue"": ""John""}]"

sUrl = "https://www.dummyurl.com/lead"
Xmlhttp.open "POST", sUrl, False
Xmlhttp.setRequestHeader "userName", "****"
Xmlhttp.setRequestHeader "password", "****"
Xmlhttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
Xmlhttp.setRequestHeader "Content-Type", "application/json; charset=utf-8"

Xmlhttp.send strjsontosend
domResponse = Xmlhttp.responseText
Text1.Text = Xmlhttp.responseText

完整示例:

arrayList.set(2, new double[]{arrayList.get(2)[0], 4.4});

输出:

public static void main(String[] args) {
    List<double[]> arrayList = new ArrayList<double[]>();
    arrayList.add(new double[]{0.0, 1.0});
    arrayList.add(new double[]{2.0, 5.0});
    arrayList.add(new double[]{3.0, 8.0});

    System.out.println("Before:");
    for (double[] d : arrayList) {
        System.out.println(d[0] + ", " + d[1]);
    }

    arrayList.set(2, new double[]{arrayList.get(2)[0], 4.4});

    System.out.println("After:");
    for (double[] d : arrayList) {
        System.out.println(d[0] + ", " + d[1]);
    }
}

答案 3 :(得分:0)

我分析您的问题并执行此类程序。您必须获取所有属性,然后进行编辑。使用HashMap进行此类操作是最好的方法。我希望下面的代码可以帮助您...

import java.util.ArrayList;
import java.util.HashMap;

public class RectangleL {

    public static void main(String args[])
    {
        ArrayList<HashMap<String,String>> lstShap = new ArrayList<>();
        HashMap<String,String> shape1 = new HashMap<>();
        HashMap<String,String> shape2 = new HashMap<>();
        lstShap.clear();
        shape1.put("width","30");
        shape1.put("height","40");
        shape1.put("infected","false");
        lstShap.add(0,shape1);

        shape2.put("width","20");
        shape2.put("height","49");
        shape2.put("infected","false");
        lstShap.add(1,shape2);

        System.out.println(lstShap.toString());
        shape1=lstShap.get(1);
        System.out.println(shape1.toString());
        shape1.put("infected","true");
        lstShap.set(1,shape1);

        System.out.println(lstShap.toString());
    }
}