[英]How to get ArrayList value from a Object ArrayList in java?
[英]How to get value from arraylist?
我正在嘗試獲取一個URL-我正在獲取的URL-和一些我存儲在兩個變量中的值。 我將這些變量放入了清單。 現在,我想在我的jsp頁面上打印該數組列表。 限制:我想一次打印出前50個值,幾秒鍾后再打印下100個值。 但是不應顯示先前的值,然后應顯示下一個50的值,並且應顯示從起始值開始的私有值。
這是我的jsp代碼
<div class="push">
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor='66A8FF'>
<%
URL url;
try {
// get URL content
String a="http://122.160.81.37:8080/mandic/commoditywise?c=paddy";
url = new URL(a);
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuffer sb=new StringBuffer();
String inputLine;
ArrayList<String> list1=new ArrayList<String>();
ArrayList<String> list2=new ArrayList<String>();
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
String s=inputLine.replace("|", "\n");
s=s.replace("~"," ");
StringTokenizer str = new StringTokenizer(s);
while(str.hasMoreTokens())
{
String mandi = str.nextElement().toString();
String price = str.nextElement().toString();
list1.add(mandi);
list2.add(price);
}
}
%>
<%
String item1 = null;
int i=0;
int j=0;
for ( i= 0; i < list1.size(); i++)
{
%>
<tr bgcolor="0F57FF" style="border-collapse:collapse">
<td width="50%" height="50px" align="center" style="font-size:24px"><font color="#fff"><%= list1.get(i)%></font></td>
<%
for ( j = 0; j < list2.size(); j++)
%>
<td width="50%" height="50px" align="center" style="font-size:24px"><font color="#fff"><%= list2.get(j)%></font></td>
</tr>
<%
}
br.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
%>
</table>
</div>
如何獲得輸出?
提前致謝
您必須將列表存儲在會話中,然后在一定間隔內刷新jsp。 每次您有兩個列表時,一個在會話中,第二個是您當前獲取的列表。
現在,如果要從arraylist中刪除常見(顯示新添加的)元素,則必須執行此操作。
1.合並兩個數組(新舊數組)
2.使它們相交
3.從聯合中減去交集即可得到結果
// suppose you have two list as below
List<Integer> list1 = Arrays.asList(1, 2, 3, 4);
List<Integer> list2 = Arrays.asList(2, 3, 4, 6, 7);
// Prepare a union
List<Integer> union = new ArrayList<Integer>(list1);
union.addAll(list2);
// Prepare an intersection
List<Integer> intersection = new ArrayList<Integer>(list1);
intersection.retainAll(list2);
// Subtract the intersection from the union
union.removeAll(intersection);
// Print the result
for (Integer n : union) {
System.out.println(n);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.