int [] [] convert --to - >矢量<矢量<双>> [英] int [] [] convert --to--> Vector<Vector<Double>>

查看:137
本文介绍了int [] [] convert --to - >矢量<矢量<双>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 integer [] [] 转换为 Vector< Vector< Double>> 。经过很多阅读,似乎没有人在网上留下可搜索的帖子,这是一个这样的性质。很多int向量双向矢量,数组列表到矢量等。很遗憾,我没有找到我正在寻找。所以你们中的任何一个人都知道一个适合的方法吗?我正在考虑将我的 int [] [] 转换为字符串,然后将其转换为 vector< vector< Double>> 。意见?这样的东西是有用的,即将我的数组转换为对象数组

  Object [] a1d = {Hello World,new Date(),Calendar.getInstance ),}; 
// Arrays.asList(Object []) - >列表
列表l = Arrays.asList(a1d);

// Vector contstructor take Collection
//列表是Collection的一个子类
Vector v;
v = new Vector(l);

//或者更简单:
v = new Vector(Arrays.asList(a1d));

否则你能给我一个更好的例子,可能会有更少的步骤?感谢Bunch再次。

解决方案

Vector是一个不被弃用但不再使用的旧类。使用ArrayList。



您应该使用LIst界面,而不是使用具体的Vector类。接口上的程序,而不是实现。



此外,重复这样的转换显示缺乏设计。将数据封装成每次需要新功能时不需要转换的可用对象。



如果您真的需要这样做:use loops:

  int [] [] array = ...; 
列表<列表< Double>> outer = new Vector< List&Double>>(); (int [] row:array)
{
列表< Double> inner = new Vector< Double>(); (int i:row)
{
inner.add(Double.valueOf(i));
}
outer.add(inner);
}

从int转换为STring,然后从String转换为Double是浪费的。 p>

I would like to convert an integer [] [] to a Vector<Vector<Double>>. After much reading, it seems no one has left a searchable post on the web for something of this nature. plenty of int vector to double vector, arraylist to vector, etc. Sadly I haven't found what i am looking for. So..Do any of you folks know an appropriate method for this? I was thinking of converting my int[][] to strings then convert that to vector<vector<Double>>. Opinions? Would something like this be useful, ie. converting my array to object array

Object[] a1d = { "Hello World", new Date(), Calendar.getInstance(), };
// Arrays.asList(Object[]) --> List
List l = Arrays.asList(a1d);

// Vector contstructor takes Collection
// List is a subclass of Collection
Vector v;
v = new Vector(l);

// Or, more simply:
v = new Vector(Arrays.asList(a1d));

Otherwise could you give me a better example that may have less steps? Thanks a Bunch again.

解决方案

Vector is an old class that is not deprecated but shouldn't be used anymore. Use ArrayList instead.

You should use the LIst interface rather than using the concrete Vector class. Program on interfaces, not on implementations.

Moreover, having repeating conversions like this shows a lack of design. Encapsulate your data into usable objects that don't need conversion each time you need a new functionality.

If you really need to do this: use loops:

int[][] array = ...;
List<List<Double>> outer = new Vector<List<Double>>();
for (int[] row : array) {
    List<Double> inner = new Vector<Double>();
    for (int i : row) {
        inner.add(Double.valueOf(i));
    }
    outer.add(inner);
}

Transforming from int to STring and then from String to Double is wasteful.

这篇关于int [] [] convert --to - &gt;矢量&lt;矢量&lt;双&GT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆