
1个回答
展开全部
可以到SUN网站上去找例子,链接
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html
————————————————————
试一下:
import java.lang.*;
import java.util.*;
public class TestList
{
public TestList(){
ArrayList myArrayList = new ArrayList();
String[][] str_data = new String[][] {
{"A01","A0101,A0102"},
{"A0102","A010201,A010202,A010203,A010204,A010205"},
{"A02","A0201,A0202"},
{"A0201","A0101,A04"},
{"A0202","A020201,A020202,A020203,A020204,A020205"},
{"A020201","A010201,A04"},
{"A020202","A010202,A04"},
{"A020203","A010203,A04"},
{"A020204","A010204,A04"},
{"A020205","A010205,A04"},
{"A03","A0201,A0301,A020201,A030201,A020202,A030202,A020203,A030203,A020204,A030204,A020205,A030205,A02"},
{"A0302","A020201,A030201,A020202,A030202,A020203,A030203,A020204,A030204,A020205,A030205,A0202"},
{"A06","A01,A05"},
{"A0601","A06,A0602"},
{"A0602","A08"},
{"A07","A0601,A11"},
{"A09","A0901,A0902"},
{"A12","A07,A09,A08,A10,A06"},
{"A1201","A07,A09,A0601"},
{"A1202","A08,A10,A0602"}
};
for(int i=0;i<str_data.length;i++)
{
if(myArrayList.size()==0)
{
myArrayList.add(str_data[i][0]); continue;
}
String[] str_belong = str_data[i][1].split(","); int li_point = 0;
boolean bo_find = false;
for(int j=0;j<str_belong.length;j++){
for(int k=0;k<myArrayList.size();k++) //遍历ArrayList
{
int li_aa = myArrayList.indexOf(str_belong[j]);
if(li_aa>=0) { bo_find=true; } if(li_aa>li_point) { li_point=li_aa; } }
}
if(bo_find){
myArrayList.add(li_point+1,str_data[i][0]);
}
else
{
myArrayList.add(0,str_data[i][0]); }
}
for(int i=0;i<myArrayList.size();i++)
{
String str_code = String.valueOf(myArrayList.get(i));
String str_formual = "";
for(int j=0;j<str_data.length;j++)
{
if(str_data[j][0].equals(str_code)) { str_formual=str_data[j][1]; }
}
System.out.println(str_code + "; " + str_formual); //输出记录
}
}
public static void main(String[] args) { new TestList(); }
}
从UE中粘过来有点乱,你整一下。
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html
————————————————————
试一下:
import java.lang.*;
import java.util.*;
public class TestList
{
public TestList(){
ArrayList myArrayList = new ArrayList();
String[][] str_data = new String[][] {
{"A01","A0101,A0102"},
{"A0102","A010201,A010202,A010203,A010204,A010205"},
{"A02","A0201,A0202"},
{"A0201","A0101,A04"},
{"A0202","A020201,A020202,A020203,A020204,A020205"},
{"A020201","A010201,A04"},
{"A020202","A010202,A04"},
{"A020203","A010203,A04"},
{"A020204","A010204,A04"},
{"A020205","A010205,A04"},
{"A03","A0201,A0301,A020201,A030201,A020202,A030202,A020203,A030203,A020204,A030204,A020205,A030205,A02"},
{"A0302","A020201,A030201,A020202,A030202,A020203,A030203,A020204,A030204,A020205,A030205,A0202"},
{"A06","A01,A05"},
{"A0601","A06,A0602"},
{"A0602","A08"},
{"A07","A0601,A11"},
{"A09","A0901,A0902"},
{"A12","A07,A09,A08,A10,A06"},
{"A1201","A07,A09,A0601"},
{"A1202","A08,A10,A0602"}
};
for(int i=0;i<str_data.length;i++)
{
if(myArrayList.size()==0)
{
myArrayList.add(str_data[i][0]); continue;
}
String[] str_belong = str_data[i][1].split(","); int li_point = 0;
boolean bo_find = false;
for(int j=0;j<str_belong.length;j++){
for(int k=0;k<myArrayList.size();k++) //遍历ArrayList
{
int li_aa = myArrayList.indexOf(str_belong[j]);
if(li_aa>=0) { bo_find=true; } if(li_aa>li_point) { li_point=li_aa; } }
}
if(bo_find){
myArrayList.add(li_point+1,str_data[i][0]);
}
else
{
myArrayList.add(0,str_data[i][0]); }
}
for(int i=0;i<myArrayList.size();i++)
{
String str_code = String.valueOf(myArrayList.get(i));
String str_formual = "";
for(int j=0;j<str_data.length;j++)
{
if(str_data[j][0].equals(str_code)) { str_formual=str_data[j][1]; }
}
System.out.println(str_code + "; " + str_formual); //输出记录
}
}
public static void main(String[] args) { new TestList(); }
}
从UE中粘过来有点乱,你整一下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询