问题描述
我已经写了一个程序,它给了我三个arrays.A字符串数组和两个救济金阵列....
但我想将它们保存在一件事(我不知道这是否会是一个数组或矩阵).....
I have written a program which gives me three arrays.A string array and two dole arrays....But I want to save them in one thing(I don't know if it would be an array or matrix).....
Forexample:
我有一个文件的读取与输入的是一样的东西:
Forexample:I have a file to read and the input is something like:
Apple 2.3 4.5
Orange 3.0 2.1
Pear 2.9 9.6
etc......
我已经进行了三次阵列,存储字符串和其他两家店双打的两列...
I already made three arrays, one that stores the name of strings and the other two stores the two columns of the doubles...
但我想整行(苹果2.3 4.5)储存在同一个事情,所以,如果我想找到我的苹果也获得苹果的相关值.....
可以请你们给我一个提示我该怎么办呢?
我认为有三个diminutional阵列,但我无法弄清楚如何初始化,因为它有一个字符串值和两个双打......
But I want to store the whole row "(apple 2.3 4.5)" in one thing so that if I want to find apple I also get related values of apple.....Can you please guys give me a hint how can I do that?I thought of having three diminutional array but I could not figure out how to initialise because it will have one string value and two doubles......
我不知道该怎么办....
任何帮助将是非常美联社preciated ....
先谢谢了。
I have no clue what to do....Any help would be highly appreciated....Thanks in advance.
推荐答案
一个很好的通用的解决方案:
A nice generic solution:
public class Triple<L, K, V> {
private final L first;
private final K second;
private final V third;
public Triple(L first, K second, V third) {
this.first = first;
this.second = second;
this.third = third;
}
public L getFirst() {
return this.first;
}
public K getSecond() {
return this.second;
}
public V getThird() {
return this.third;
}
}
哪些可实施为这样:
Which can be implemented as such:
Triple<String, Integer, Integer> myTriple = new Triple<>("Hello world", 42, 666);
但真正的概念重新presenting数据点为对象在code。如果你有一组数据(我有一个字符串和两个整数意味着的东西的),那么你会希望它封装一个类下。
But the real concept here is representing a point of data as an object in your code. If you have a set of data ("I have a string and two ints that mean something"), then you would want to encapsulate it under a single class.
这篇关于存储字符串和两个双打的java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!