62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class StringTest {
/**
* 测试
* @param args
*/
public static void main(String[] args) {
String value = "";
Map map = new LinkedHashMap();
for(int i = 0; i < 3 ;i++){
List list = new ArrayList();
value = getValue(i);
for(int j = 0 ; j < 3; j++){
Map vm = new LinkedHashMap();
vm.put("name", value+j);
list.add(vm);
}
map.put("key"+i,list);
}
List returnList = getControlFormulaShow(map);
}
/**
*
* @param i
* @return
*/
public static String getValue(int i){
String returnValue = "";
switch(i){
case 0:
returnValue = "A";
break;
case 1:
returnValue = "B";
break;
case 2:
returnValue = "C";
break;
default:
returnValue = "";
break;
}
return returnValue;
}
/**
*
* @param map
* @return
*/
public static List getControlFormulaShow(Map map){
List returnList = new ArrayList();
Iterator it = map.keySet().iterator();
int colNum= 0;
int f = 1;
int preSize = 1;
while(it.hasNext()){
String key = (String) it.next();
List list = (List)map.get(key);
f = f * list.size();
colNum = colNum + f;
for(int i = 0; i < preSize ;i++){
for(int j = 0;j < list.size();j++){
//这里怎么插入?
returnList.add(returnList.size(), list.get(j));
}
}
preSize = list.size();
}
return returnList;
}
}
/**
* @param map
* @return
*/
public static List getControlFormulaShow(Map map)
{
List returnList = new ArrayList();
Iterator it = map.entrySet().iterator();
List tempList = new ArrayList();
for (int i = 0; i < map.size(); i++)
{
tempList.add(((Entry)it.next()).getValue());
}
for(int k = 0; k < map.size(); k++)
{
returnList.add(((List)tempList.get(0)).get(k));
for (int i = 0; i < ((List)tempList.get(1)).size(); i++)
{
returnList.add(((List)tempList.get(1)).get(i));
for (int j = 0; j < ((List)tempList.get(2)).size(); j++)
{
returnList.add(((List)tempList.get(2)).get(j));
}
}
}
return returnList;
}
package com.test;
import java.util.ArrayList;
import java.util.List;
public class CList {
public static void main(String[] arg) {
CList c = new CList();
List<String> list = new ArrayList<String>();
c.set(list, c.array, 0);
for (String l : list) {
System.out.println(l);
}
}
public String[][] array = new String[][] {
{"name=A0", "name=A1", "name=A2"},
{"name=B0", "name=B1", "name=B2"},
{"name=C0", "name=C1", "name=C2"},
{"name=D0", "name=D1", "name=D2"}
};
private void set(List<String> list, String[][] array, int index){
for (int i = 0; i < array[index].length; i++) {
String blank = "";
for (int j = 0; j < index; j++) {
blank += " ";
}
list.add(blank + array[index][i]);
if (index < array.length - 1) {
this.set(list, array, index + 1);
}
}
}
}