Java Array split:快速分割数组索引列表的方法

时间:2015-03-01 17:47:01

标签: java arrays

我有Topic1000Url类

public class Topic1000Url {

     private int [] url_id;
     private double [] sum_url_Tsim;    
}

问题是我想让分裂函数可以拆分2个数组。

1 个答案:

答案 0 :(得分:0)

public static void split(TopicLinkdata source_sim_arr,
        TopicLinkdata trainingSet_sim_arr, TopicLinkdata testData_sim_arr)
{
    trainingSet_sim_arr.setUrl_id(Arrays.copyOfRange(
            source_sim_arr.getUrl_id(), 0,
            source_sim_arr.getUrl_id().length / 2));
    testData_sim_arr.setUrl_id(Arrays.copyOfRange(
            source_sim_arr.getUrl_id(),
            source_sim_arr.getUrl_id().length / 2,
            source_sim_arr.getUrl_id().length));

    trainingSet_sim_arr.setSum_url_Tsim(Arrays.copyOfRange(
            source_sim_arr.getSum_url_Tsim(), 0,
            source_sim_arr.getSum_url_Tsim().length / 2));
    testData_sim_arr.setSum_url_Tsim(Arrays.copyOfRange(
            source_sim_arr.getSum_url_Tsim(),
            source_sim_arr.getSum_url_Tsim().length / 2,
            source_sim_arr.getSum_url_Tsim().length));
}