Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 番石榴和arraylist加法表_Java_Arraylist_Hashmap_Guava - Fatal编程技术网

Java 番石榴和arraylist加法表

Java 番石榴和arraylist加法表,java,arraylist,hashmap,guava,Java,Arraylist,Hashmap,Guava,我有这个程序,我想收集ArrayListOperationable中的值和表employeeYearsOfService中的值,我想将结果存储在包含RowKey和result的HashMap中 我不知道怎么做。这就是我想要的 代码 public class collaborativAlgorithme { Table<String, String, Double> employeeYearsOfService = HashBasedTable.creat

我有这个程序,我想收集ArrayList
Operationable
中的值和表
employeeYearsOfService
中的值,我想将结果存储在包含RowKey和result的
HashMap

我不知道怎么做。这就是我想要的

代码

    public class collaborativAlgorithme {

    Table<String, String, Double> employeeYearsOfService = 
    HashBasedTable.create();

    public static void main(String[] args) {
    List<Double> operatCible = new ArrayList<Double>();
    operatCible.add(4.1);
    operatCible.add(5.0);
    System.out.println(operatCible);

    Table<String, String, Double> employeeYearsOfService = 
    HashBasedTable.create();

    employeeYearsOfService.put("AT&T", "Stacy Lerner", 1.4);
    employeeYearsOfService.put("Microsoft", "Stacy Lerner", 3.5);
    employeeYearsOfService.put("Microsoft", "Bill Smith", 13.2);
    employeeYearsOfService.put("Google", "Stacy Lerner", 11.5);

    employeeYearsOfService.put("AT&T", "Bill Smith", 2.0);
    employeeYearsOfService.put("Google", "Bill Smith", 9.75);
    System.out.println(employeeYearsOfService.rowKeySet());
    HashMap<String,Integer> result=new HashMap<String,Integer>;
    System.out.println(employeeYearsOfService);
    Map<String, Double> attEmployees = employeeYearsOfService.row("AT&T");
    for (Map.Entry<String, Double> employee : attEmployees.entrySet()) {
        // what i do??
        // sum values arraylist and values table
        System.out.println("Employee Name: " + employee.getKey() + ", Years 
     of Service: " + employee.getValue());
    }
   }
 }
公共类协作算法{
表employeeYearsOfService=
HashBasedTable.create();
公共静态void main(字符串[]args){
List Operationable=new ArrayList();
可操作。添加(4.1);
可操作。添加(5.0);
系统输出打印LN(可操作);
表employeeYearsOfService=
HashBasedTable.create();
《雇员服务年鉴》put(“AT&T”,“Stacy Lerner”,1.4);
employeeyearsoffice.put(“微软”、“斯泰西·勒纳”,3.5);
“微软”、“比尔·史密斯”,13.2);
“谷歌”,“斯泰西·勒纳”,11.5);
“美国电话电报公司”、“比尔·史密斯”,2.0);
“谷歌”,“比尔·史密斯”,9.75);
System.out.println(employeeyearsoffice.rowKeySet());
HashMap结果=新的HashMap;
System.out.println(员工服务年限);
Map attEmployees=employeeyearsofsofservice.row(“AT&T”);
对于(Map.Entry employee:attEmployees.entrySet()){
//我做什么??
//和值数组列表和值表
System.out.println(“员工姓名:“+Employee.getKey()+”,年
服务类型:“+employee.getValue());
}
}
}
我解决了我的问题 我添加了一些其他内容,如(sqrt)。。。。 这是密码

    int k = 0;
    Double sum = 0.0;//cosine similarity
    Double sum2 = 0.0;
    System.out.println(employeeYearsOfService);
    for (String key : employeeYearsOfService.rowKeySet()) {
        HashMap<String, Double> hm = new HashMap<String, Double>();
        for (Entry<String, Double> employee : 
        employeeYearsOfService.row(key).entrySet()) {
            sum += employee.getValue() * operatCible.get(k);
            sum2+=employee.getValue();
            k++;
        }
        k = 0;

        System.out.println(sum);
        System.out.println("----");
        System.out.println(sqrt(sum2));
        hm.put(key, sum);
        sum = 0.0;

        System.out.println(hm);
    }


}
intk=0;
双和=0.0//余弦相似性
双sum2=0.0;
System.out.println(员工服务年限);
for(字符串键:employeeYearsOfService.rowKeySet()){
HashMap hm=新的HashMap();
入职员工:
employeeyearsoffice.row(key.entrySet()){
sum+=employee.getValue()*可操作的.get(k);
sum2+=employee.getValue();
k++;
}
k=0;
系统输出打印项数(总和);
System.out.println(“---”);
系统输出打印LN(sqrt(sum2));
hm.put(键、和);
总和=0.0;
系统输出打印项次(hm);
}
}
你可以

         HashMap<String, Double> hm = new HashMap<String, Double>();
         System.out.println(employeeYearsOfService);
         for (String key : employeeYearsOfService.rowKeySet()) {

        for (Entry<String, Double> employee : 
        employeeYearsOfService.row(key).entrySet()) {
            sum += employee.getValue() + operatCible.get(k);

            k++;
        }
        k = 0;

        System.out.println(sum);


        hm.put(key, sum);


    }
HashMap hm=newhashmap();
System.out.println(员工服务年限);
for(字符串键:employeeYearsOfService.rowKeySet()){
入职员工:
employeeyearsoffice.row(key.entrySet()){
sum+=employee.getValue()+operatible.get(k);
k++;
}
k=0;
系统输出打印项数(总和);
hm.put(键、和);
}

不是你想做什么-你有价值,只是求和?为什么地图中的
Integer
,而不是
Double
operatible
及其值的处理方法是什么?@Xaerxess我只想对值求和,我在map中弄错了
Double
,处理方法是将
ArrayList
中的值与
表中的值求和,所以只需将
employee.getValue()
中循环中的数字与列表中的数字求和即可?您在使用Java 8吗?@Xaerxess谢谢,但是如果我想对我的
表中的每一行进行求和,而不仅仅是
员工服务年数。行(“AT&T”)
,怎么做呢,我在Java中是乞丐