首页 > 解决方案 > 我想将 iphone 名称及其价格存储在 excel 表中。对于相同的 iphone 名称在一张 excel 表中疼痛

问题描述

转到 Flipkart 搜索 iphone 以获取相同的 i 电话名称为另一个 iphone 名称创建一个 excel 表创建另一个 excel 表。

代码如下所示:

public static void main(String[] args) {

        Set<String> uniquename = new HashSet<String>();
        ArrayList<String[]> data1 = new  ArrayList<String[]>();
        Map<String,List<String[]> > hashmap = new HashMap<String,List<String[]> >();
        data1.add( new String[] {"Apple iPhone 8 Plus (Space Grey, 64 GB)","56000"});
        data1.add(new String[] {"Apple iPhone 6 (Grey, 128 GB)","47000"});
        data1.add(new String[] {"Apple iPhone XS (Space Grey, 512 GB)","28000"});
        data1.add(new String[] {"Apple iPhone XS (Space Grey, 512 GB)","29000"});
        data1.add(new String[] {"Apple iPhone 7 Plus (Gold, 128 GB)","19000"});
        data1.add(new String[] {"Apple iPhone 7 Plus (Gold, 128 GB)","18000"});
        for(String[] data:data1) {
            uniquename.add(data[0].replace("(", "#").split("#")[0] );
        }

            System.out.println(uniquename);
            System.out.println(uniquename.size());
            System.out.println(data1.size());


            for(String name : uniquename) {
                List<String[]> temp =new ArrayList<String[]>();
                    for(String[] d : data1) {
                        if(name==d[0].substring(0, 19)) {
                            temp.add(d);


                        }
                        hashmap.put(name, temp);
                    }

                    }
            Set keys = hashmap.keySet();
             System.out.println("All keys are: " + keys);

                    List<String[]> value = hashmap.get(keys);
                    for(String[] val : value) {
                        System.out.println(value);      
}
}

提前谢谢。

标签: javaselenium

解决方案


推荐阅读