- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 java 中有一个字符串数组的 ArrayList,名为:
List<String[]> initialList = new ArrayList<String[]>();
它包含以下数据(这是它的一个片段,它实际上包含大约 900 行,其中还包括 Charlie、Delta、Echo,每行都与这些数据具有相同的结构:
[Alpha, A1, 1, null]
[Alpha, A1, 2, null]
[Alpha, A1, 3, null]
[Alpha, A1, 4, null]
[Alpha, A1, 5, null]
[Alpha, A1, 6, null]
[Alpha, A1, 7, null]
[Alpha, A1, 8, null]
[Alpha, A1, 9, null]
[Alpha, A1, 10, null]
[Alpha, A1, 11, null]
[Alpha, A1, 12, null]
[Alpha, A1, 13, null]
[Alpha, A1, 14, null]
[Alpha, A1, 15, null]
[Alpha, A1, 16, null]
[Alpha, A1, 17, null]
[Alpha, A1, 18, null]
[Alpha, A1, 19, null]
[Alpha, A1, 20, null]
[Alpha, A1, 21, null]
[Alpha, A1, 22, null]
[Alpha, A1, 23, null]
[Alpha, A1, 24, null]
[Alpha, A1, 25, null]
[Alpha, A1, 26, null]
[Alpha, A1, 27, null]
[Alpha, A1, 28, null]
[Alpha, A1, 29, null]
[Alpha, A1, 30, null]
[Alpha, A1, 31, null]
[Alpha, A1, 32, null]
[Alpha, A1, 33, null]
[Alpha, A1, 34, null]
[Alpha, A1, 35, null]
[Alpha, A1, 36, null]
[Alpha, A1, 37, null]
[Alpha, A1, 38, null]
[Alpha, A1, 39, null]
[Alpha, A1, 40, null]
[Alpha, A1, 41, null]
[Alpha, A1, 42, null]
[Alpha, A1, 43, null]
[Alpha, A1, 44, null]
[Alpha, A1, 45, null]
[Alpha, A1, 46, null]
[Alpha, A1, 47, null]
[Alpha, A1, 48, null]
[Alpha, A1, 49, null]
[Alpha, A1, 50, null]
[Alpha, A1, 51, null]
[Alpha, A1, 52, null]
[Alpha, A1, 53, null]
[Alpha, A1, 54, null]
[Alpha, A2, 1, null]
[Alpha, A2, 2, null]
[Alpha, A2, 3, null]
[Alpha, A2, 4, null]
[Alpha, A2, 5, null]
[Alpha, A2, 6, null]
[Alpha, A2, 7, null]
[Alpha, A2, 8, null]
[Alpha, A2, 9, null]
[Alpha, A2, 10, null]
[Alpha, A2, 11, null]
[Alpha, A2, 12, null]
[Alpha, A2, 13, null]
[Alpha, A2, 14, null]
[Alpha, A2, 15, null]
[Alpha, A2, 16, null]
[Alpha, A2, 17, null]
[Alpha, A2, 18, null]
[Alpha, A2, 19, null]
[Alpha, A2, 20, null]
[Alpha, A2, 21, null]
[Alpha, A2, 22, null]
[Alpha, A2, 23, null]
[Alpha, A2, 24, null]
[Alpha, A2, 25, null]
[Alpha, A2, 26, null]
[Alpha, A2, 27, null]
[Alpha, A2, 28, null]
[Alpha, A2, 29, null]
[Alpha, A2, 30, null]
[Alpha, A2, 31, null]
[Alpha, A2, 32, null]
[Alpha, A2, 33, null]
[Alpha, A2, 34, null]
[Alpha, A2, 35, null]
[Alpha, A2, 36, null]
[Alpha, A2, 37, null]
[Alpha, A2, 38, null]
[Alpha, A2, 39, null]
[Alpha, A2, 40, null]
[Alpha, A2, 41, null]
[Alpha, A2, 42, null]
[Alpha, A2, 43, null]
[Alpha, A2, 44, null]
[Alpha, A2, 45, null]
[Alpha, A2, 46, null]
[Alpha, A2, 47, null]
[Alpha, A2, 48, null]
[Alpha, A2, 49, null]
[Alpha, A2, 50, null]
[Alpha, A2, 51, null]
[Alpha, A2, 52, null]
[Alpha, A2, 53, null]
[Alpha, A2, 54, null]
[Alpha, A3, 1, null]
[Alpha, A3, 2, null]
[Alpha, A3, 3, null]
[Alpha, A3, 4, null]
[Alpha, A3, 5, null]
[Alpha, A3, 6, null]
[Alpha, A3, 7, null]
[Alpha, A3, 8, null]
[Alpha, A3, 9, null]
[Alpha, A3, 10, null]
[Alpha, A3, 11, null]
[Alpha, A3, 12, null]
[Alpha, A3, 13, null]
[Alpha, A3, 14, null]
[Alpha, A3, 15, null]
[Alpha, A3, 16, null]
[Alpha, A3, 17, null]
[Alpha, A3, 18, null]
[Alpha, A3, 19, null]
[Alpha, A3, 20, null]
[Alpha, A3, 21, null]
[Alpha, A3, 22, null]
[Alpha, A3, 23, null]
[Alpha, A3, 24, null]
[Alpha, A3, 25, null]
[Alpha, A3, 26, null]
[Alpha, A3, 27, null]
[Alpha, A3, 28, null]
[Alpha, A3, 29, null]
[Alpha, A3, 30, null]
[Alpha, A3, 31, null]
[Alpha, A3, 32, null]
[Alpha, A3, 33, null]
[Alpha, A3, 34, null]
[Alpha, A3, 35, null]
[Alpha, A3, 36, null]
[Alpha, A3, 37, null]
[Alpha, A3, 38, null]
[Alpha, A3, 39, null]
[Alpha, A3, 40, null]
[Alpha, A3, 41, null]
[Alpha, A3, 42, null]
[Alpha, A3, 43, null]
[Alpha, A3, 44, null]
[Alpha, A3, 45, null]
[Alpha, A3, 46, null]
[Alpha, A3, 47, null]
[Alpha, A3, 48, null]
[Alpha, A3, 49, null]
[Alpha, A3, 50, null]
[Alpha, A3, 51, null]
[Alpha, A3, 52, null]
[Alpha, A3, 53, null]
[Alpha, A3, 54, null]
[Alpha, A3, 55, null]
[Alpha, A3, 56, null]
[Alpha, A3, 57, null]
[Alpha, A3, 58, null]
[Alpha, A3, 59, null]
[Alpha, A3, 60, null]
[Alpha, A4, 1, null]
[Alpha, A4, 2, null]
[Alpha, A4, 3, null]
[Alpha, A4, 4, null]
[Alpha, A4, 5, null]
[Alpha, A4, 6, null]
[Alpha, A4, 7, null]
[Alpha, A4, 8, null]
[Alpha, A4, 9, null]
[Alpha, A4, 10, null]
[Alpha, A4, 11, null]
[Alpha, A4, 12, null]
[Alpha, A4, 13, null]
[Alpha, A4, 14, null]
[Alpha, A4, 15, null]
[Alpha, A4, 16, null]
[Alpha, A4, 17, null]
[Alpha, A4, 18, null]
[Alpha, A4, 19, null]
[Alpha, A4, 20, null]
[Alpha, A4, 21, null]
[Alpha, A4, 22, null]
[Alpha, A4, 23, null]
[Alpha, A4, 24, null]
[Alpha, A4, 25, null]
[Alpha, A4, 26, null]
[Alpha, A4, 27, null]
[Alpha, A4, 28, null]
[Alpha, A4, 29, null]
[Alpha, A4, 30, null]
[Alpha, A4, 31, null]
[Alpha, A4, 32, null]
[Alpha, A4, 33, null]
[Alpha, A4, 34, null]
[Alpha, A4, 35, null]
[Alpha, A4, 36, null]
[Alpha, A4, 37, null]
[Alpha, A4, 38, null]
[Alpha, A4, 39, null]
[Alpha, A4, 40, null]
[Alpha, A4, 41, null]
[Alpha, A4, 42, null]
[Alpha, A4, 43, null]
[Alpha, A4, 44, null]
[Alpha, A4, 45, null]
[Alpha, A4, 46, null]
[Alpha, A4, 47, null]
[Alpha, A4, 48, null]
[Alpha, A4, 49, null]
[Alpha, A4, 50, null]
[Alpha, A4, 51, null]
[Alpha, A4, 52, null]
[Alpha, A4, 53, null]
[Alpha, A4, 54, null]
[Alpha, A4, 55, null]
[Alpha, A4, 56, null]
[Alpha, A4, 57, null]
[Alpha, A4, 58, null]
[Alpha, A4, 59, null]
[Alpha, A4, 60, null]
[Bravo, B1, 1, null]
[Bravo, B1, 2, null]
[Bravo, B1, 3, null]
[Bravo, B1, 4, null]
[Bravo, B1, 5, null]
[Bravo, B1, 6, null]
[Bravo, B1, 7, null]
[Bravo, B1, 8, null]
[Bravo, B1, 9, null]
[Bravo, B1, 10, null]
[Bravo, B1, 11, null]
[Bravo, B1, 12, null]
[Bravo, B1, 13, null]
[Bravo, B1, 14, null]
[Bravo, B1, 15, null]
[Bravo, B1, 16, null]
[Bravo, B1, 17, null]
[Bravo, B1, 18, null]
[Bravo, B1, 19, null]
[Bravo, B1, 20, null]
[Bravo, B1, 21, null]
[Bravo, B1, 22, null]
[Bravo, B1, 23, null]
[Bravo, B1, 24, null]
[Bravo, B1, 25, null]
[Bravo, B1, 26, null]
[Bravo, B1, 27, null]
[Bravo, B1, 28, null]
[Bravo, B1, 29, null]
[Bravo, B1, 30, null]
[Bravo, B1, 31, null]
[Bravo, B1, 32, null]
[Bravo, B1, 33, null]
[Bravo, B1, 34, null]
[Bravo, B1, 35, null]
[Bravo, B1, 36, null]
[Bravo, B1, 37, null]
[Bravo, B1, 38, null]
[Bravo, B1, 39, null]
[Bravo, B1, 40, null]
[Bravo, B1, 41, null]
[Bravo, B1, 42, null]
[Bravo, B1, 43, null]
[Bravo, B1, 44, null]
[Bravo, B1, 45, null]
[Bravo, B1, 46, null]
[Bravo, B1, 47, null]
[Bravo, B1, 48, null]
[Bravo, B1, 49, null]
[Bravo, B1, 50, null]
[Bravo, B1, 51, null]
[Bravo, B1, 52, null]
[Bravo, B1, 53, null]
[Bravo, B1, 54, null]
[Bravo, B1, 55, null]
[Bravo, B1, 56, null]
[Bravo, B1, 57, null]
[Bravo, B1, 58, null]
[Bravo, B1, 59, null]
[Bravo, B1, 60, null]
[Bravo, B2, 1, null]
[Bravo, B2, 2, null]
[Bravo, B2, 3, null]
[Bravo, B2, 4, null]
[Bravo, B2, 5, null]
[Bravo, B2, 6, null]
[Bravo, B2, 7, null]
[Bravo, B2, 8, null]
[Bravo, B2, 9, null]
[Bravo, B2, 10, null]
[Bravo, B2, 11, null]
[Bravo, B2, 12, null]
[Bravo, B2, 13, null]
[Bravo, B2, 14, null]
[Bravo, B2, 15, null]
[Bravo, B2, 16, null]
[Bravo, B2, 17, null]
[Bravo, B2, 18, null]
[Bravo, B2, 19, null]
[Bravo, B2, 20, null]
[Bravo, B2, 21, null]
[Bravo, B2, 22, null]
[Bravo, B2, 23, null]
[Bravo, B2, 24, null]
[Bravo, B2, 25, null]
[Bravo, B2, 26, null]
[Bravo, B2, 27, null]
[Bravo, B2, 28, null]
[Bravo, B2, 29, null]
[Bravo, B2, 30, null]
[Bravo, B2, 31, null]
[Bravo, B2, 32, null]
[Bravo, B2, 33, null]
[Bravo, B2, 34, null]
[Bravo, B2, 35, null]
[Bravo, B2, 36, null]
[Bravo, B2, 37, null]
[Bravo, B2, 38, null]
[Bravo, B2, 39, null]
[Bravo, B2, 40, null]
[Bravo, B2, 41, null]
[Bravo, B2, 42, null]
[Bravo, B2, 43, null]
[Bravo, B2, 44, null]
[Bravo, B2, 45, null]
[Bravo, B2, 46, null]
[Bravo, B2, 47, null]
[Bravo, B2, 48, null]
[Bravo, B2, 49, null]
[Bravo, B2, 50, null]
[Bravo, B2, 51, null]
[Bravo, B2, 52, null]
[Bravo, B2, 53, null]
[Bravo, B2, 54, null]
[Bravo, B2, 55, null]
[Bravo, B2, 56, null]
[Bravo, B2, 57, null]
[Bravo, B2, 58, null]
[Bravo, B2, 59, null]
[Bravo, B2, 60, null]
[Bravo, B3, 1, null]
[Bravo, B3, 2, null]
[Bravo, B3, 3, null]
[Bravo, B3, 4, null]
[Bravo, B3, 5, null]
[Bravo, B3, 6, null]
[Bravo, B3, 7, null]
[Bravo, B3, 8, null]
[Bravo, B3, 9, null]
[Bravo, B3, 10, null]
[Bravo, B3, 11, null]
[Bravo, B3, 12, null]
[Bravo, B3, 13, null]
[Bravo, B3, 14, null]
[Bravo, B3, 15, null]
[Bravo, B3, 16, null]
[Bravo, B3, 17, null]
[Bravo, B3, 18, null]
[Bravo, B3, 19, null]
[Bravo, B3, 20, null]
[Bravo, B3, 21, null]
[Bravo, B3, 22, null]
[Bravo, B3, 23, null]
[Bravo, B3, 24, null]
[Bravo, B3, 25, null]
[Bravo, B3, 26, null]
[Bravo, B3, 27, null]
[Bravo, B3, 28, null]
[Bravo, B3, 29, null]
[Bravo, B3, 30, null]
[Bravo, B3, 31, null]
[Bravo, B3, 32, null]
[Bravo, B3, 33, null]
[Bravo, B3, 34, null]
[Bravo, B3, 35, null]
[Bravo, B3, 36, null]
[Bravo, B3, 37, null]
[Bravo, B3, 38, null]
[Bravo, B3, 39, null]
[Bravo, B3, 40, null]
[Bravo, B3, 41, null]
[Bravo, B3, 42, null]
[Bravo, B3, 43, null]
[Bravo, B3, 44, null]
[Bravo, B3, 45, null]
[Bravo, B3, 46, null]
[Bravo, B3, 47, null]
[Bravo, B3, 48, null]
[Bravo, B3, 49, null]
[Bravo, B3, 50, null]
[Bravo, B3, 51, null]
[Bravo, B3, 52, null]
[Bravo, B3, 53, null]
结构如下:Alpha、Bravo、Charlie、Delta 和 Echo 是根节点,包含: (A1, A2, A3, A4) (B1, B2, B3, B4) (C1, C2, C3, C4) 等...然后每个都包含“n”个位置,每个数字包含一个人的名字。
我需要将其变成层次树结构。我尝试过以下方法:
Map<String, Set<String>> myNodes = new LinkedHashMap<String, Set<String>>();
for(String[] myArray : initialList) {
String previousNode = null;
for(String node : myArray) {
if(myNodes.get(node) == null) {
myNodes.put(node, new HashSet<String>());
}
if(previousNode != null) {
myNodes.get(previousNode).add(node);
}
previousNode = node;
}
}
但是输出如下,如您所见,这是错误的,而不是我正在寻找的内容(同样,只是完整输出的一个片段)。
Alpha : [A2, A1, A4, A3]
A1 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 19, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
1 : [null]
null : []
2 : [null]
null : []
3 : [null]
4 : [null]
5 : [null]
6 : [null]
7 : [null]
8 : [null]
9 : [null]
10 : [null]
11 : [null]
12 : [null]
13 : [null]
14 : [null]
15 : [null]
16 : [null]
17 : [null]
18 : [null]
19 : [null]
20 : [null]
21 : [null]
22 : [null]
23 : [null]
24 : [null]
25 : [null]
26 : [null]
27 : [null]
28 : [null]
29 : [null]
30 : [null]
31 : [null]
32 : [null]
33 : [null]
34 : [null]
35 : [null]
36 : [null]
37 : [null]
38 : [null]
39 : [null]
40 : [null]
41 : [null]
42 : [null]
43 : [null]
44 : [null]
45 : [null]
46 : [null]
47 : [null]
48 : [null]
49 : [null]
50 : [null]
51 : [null]
52 : [null]
53 : [null]
54 : [null]
A2 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 19, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
A3 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
55 : [null]
56 : [null]
57 : [null]
58 : [null]
59 : [null]
60 : [null]
A4 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
Bravo : [B4, B3, B2, B1]
B1 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
B2 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
B3 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
B4 : [35, 36, 33, 34, 39, 37, 38, 43, 42, 41, 40, 22, 23, 24, 25, 26, 27, 28, 29, 3, 2, 1, 7, 30, 6, 5, 32, 4, 31, 9, 8, 59, 58, 57, 56, 19, 55, 17, 18, 15, 16, 13, 14, 11, 12, 21, 20, 60, 49, 48, 45, 44, 47, 46, 10, 51, 52, 53, 54, 50]
这是使用 Map 和 LinkedHashMap,所以我也用 TreeMap 尝试过(尽管不确定这是否是我需要的):
TreeMap<String, Set<String>> myNodes = new TreeMap<String, Set<String>>();
for(String[] myArray : initialList) {
String previousNode = null;
for(String node : myArray) {
if(myNodes.get(node) == null) {
myNodes.put(node, new HashSet<String>());
}
if(previousNode != null) {
myNodes.get(previousNode).add(node);
}
previousNode = node;
}
}
但出现以下错误:
Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.getEntry(TreeMap.java:324)
at java.util.TreeMap.get(TreeMap.java:255)
我需要它分层,如上所述。我很想准确地描述它应该输出什么,但说实话,我不确定,我只知道它需要有一个层次结构并转换为 JSON,如下所述。
此外,必须将其转换为以下格式的 JSON,因此请记住这一点(同样,实际输出要大得多,这只是一个结构示例:
{
"name":"Alpha",
"children":[
{
"name":"A1",
"children":[
{
"name":"1",
"children":[
{
"name":"null",
},
]
"name":"2",
"children":[
{
"name":"null",
},
]
"name":"3",
"children":[
{
"name":"null",
},
]
},
"name":"A2",
"children":[
{
"name":"1",
"children":[
{
"name":"null",
},
]
"name":"2",
"children":[
{
"name":"null",
},
]
"name":"3",
"children":[
{
"name":"null",
},
]
},
]
},
我很感激能得到的任何帮助,因为我真的很难过。谢谢!
最佳答案
尝试运行以下代码。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
class JsonModel {
private String name;
private List<JsonModel> children;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<JsonModel> getChildren() {
return children;
}
public void setChildren(List<JsonModel> children) {
this.children = children;
}
public String toString(){
return "name: "+name + ", children: {"+children+"}";
}
}
public class Test{
public static void main(String a[])
{
ArrayList<String[]> initialList= new ArrayList<String[]>();
initialList.add(new String[]{"Alpha", "A1", "1", null});
initialList.add(new String[]{"Alpha", "A1", "2", null});
initialList.add(new String[]{"Alpha", "A2", "1", null});
initialList.add(new String[]{"Alpha", "A2", "2", null});
initialList.add(new String[]{"Beta", "A1", "1", null});
initialList.add(new String[]{"Beta", "A1", "2", null});
initialList.add(new String[]{"Beta", "A2", "1", null});
initialList.add(new String[]{"Beta", "A2", "2", null});
ArrayList<JsonModel> returnList = new ArrayList<JsonModel>();
HashMap<String,HashMap<String,JsonModel>> tempMap = new HashMap<String, HashMap<String,JsonModel>>();
HashMap<String,JsonModel> tempMapOuterMost = new HashMap<String, JsonModel>();
// eg. 1,null
JsonModel layer3Child = null;
// eg. A1,{}
JsonModel layer2Child = null;
// eg. Alpha,{}
JsonModel layer1Child = null;
for(String[] myArray: initialList){
// to set inner most object eg. 1,null
layer3Child = new JsonModel();
layer3Child.setName(myArray[2]);
JsonModel layer4Child = new JsonModel();
layer4Child.setName("PersonName");
ArrayList<JsonModel> layer4Children = new ArrayList<JsonModel>();
layer4Children.add(layer4Child);
layer3Child.setChildren(layer4Children);
// getting object of outermost model eg. Alpha,{}
if (tempMap.containsKey(myArray[0])){
layer1Child = tempMapOuterMost.get(myArray[0]);
} else {
layer1Child = new JsonModel();
layer1Child.setName(myArray[0]);
layer1Child.setChildren(new ArrayList<JsonModel>());
returnList.add(layer1Child);
tempMapOuterMost.put(myArray[0], layer1Child);
tempMap.put(myArray[0], new HashMap<String,JsonModel>());
}
// getting the object at layer 2 eg. A1,{}
if (tempMap.get(myArray[0]).containsKey(myArray[1])){
layer2Child = tempMap.get(myArray[0]).get(myArray[1]);
} else {
layer2Child = new JsonModel();
layer2Child.setName(myArray[1]);
layer2Child.setChildren(new ArrayList<JsonModel>());
layer1Child.getChildren().add(layer2Child);
tempMap.get(myArray[0]).put(myArray[1], layer2Child);
}
layer2Child.getChildren().add(layer3Child);
}
System.out.println(returnList);
}
}
关于java - 从数组生成树结构 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971926/
我正在尝试创建一个包含 int[][] 项的数组 即 int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} }; int version1Indexes[
我有一个整数数组: private int array[]; 如果我还有一个名为 add 的方法,那么以下有什么区别: public void add(int value) { array[va
当您尝试在 JavaScript 中将一个数组添加到另一个数组时,它会将其转换为一个字符串。通常,当以另一种语言执行此操作时,列表会合并。 JavaScript [1, 2] + [3, 4] = "
根据我正在阅读的教程,如果您想创建一个包含 5 列和 3 行的表格来表示这样的数据... 45 4 34 99 56 3 23 99 43 2 1 1 0 43 67 ...它说你可以使用下
我通常使用 python 编写脚本/程序,但最近开始使用 JavaScript 进行编程,并且在使用数组时遇到了一些问题。 在 python 中,当我创建一个数组并使用 for x in y 时,我得
我有一个这样的数组: temp = [ 'data1', ['data1_a','data1_b'], ['data2_a','data2_b','data2_c'] ]; // 我想使用 toStr
rent_property (table name) id fullName propertyName 1 A House Name1 2 B
这个问题在这里已经有了答案: 关闭13年前。 Possible Duplicate: In C arrays why is this true? a[5] == 5[a] array[index] 和
使用 Excel 2013。经过多年的寻找和适应,我的第一篇文章。 我正在尝试将当前 App 用户(即“John Smith”)与他的电子邮件地址“jsmith@work.com”进行匹配。 使用两个
当仅在一个边距上操作时,apply 似乎不会重新组装 3D 数组。考虑: arr 1),但对我来说仍然很奇怪,如果一个函数返回一个具有尺寸的对象,那么它们基本上会被忽略。 最佳答案 这是一个不太理
我有一个包含 GPS 坐标的 MySQL 数据库。这是我检索坐标的部分 PHP 代码; $sql = "SELECT lat, lon FROM gps_data"; $stmt=$db->query
我需要找到一种方法来执行这个操作,我有一个形状数组 [批量大小, 150, 1] 代表 batch_size 整数序列,每个序列有 150 个元素长,但在每个序列中都有很多添加的零,以使所有序列具有相
我必须通过 url 中的 json 获取文本。 层次结构如下: 对象>数组>对象>数组>对象。 我想用这段代码获取文本。但是我收到错误 :org.json.JSONException: No valu
enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
知道如何对二维字符串数组执行修剪操作,例如使用 Java 流 API 进行 3x3 并将其收集回相同维度的 3x3 数组? 重点是避免使用显式的 for 循环。 当前的解决方案只是简单地执行一个 fo
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我有来自 ASP.NET Web 服务的以下 XML 输出: 1710 1711 1712 1713
如果我有一个对象todo作为您状态的一部分,并且该对象包含数组列表,则列表内部有对象,在这些对象内部还有另一个数组listItems。如何更新数组 listItems 中 id 为“poi098”的对
我想将最大长度为 8 的 bool 数组打包成一个字节,通过网络发送它,然后将其解压回 bool 数组。已经在这里尝试了一些解决方案,但没有用。我正在使用单声道。 我制作了 BitArray,然后尝试
我们的数据库中有这个字段指示一周中的每一天的真/假标志,如下所示:'1111110' 我需要将此值转换为 boolean 数组。 为此,我编写了以下代码: char[] freqs = weekday
我是一名优秀的程序员,十分优秀!