Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

arraylist

ArrayListDemo.java
Friday, 29 July 2011 05:32
package questions;

import java.util.*;
/**
* @author Bharat Verma
*/
public class ArrayListDemo
{
public static void printArrayList (ArrayList p_arraylist)
{
System.out.println("------------------------------------------");
System.out.println("Content of ArrayList : "+p_arraylist);
System.out.println("Size of ArrayList = "+p_arraylist.size());
System.out.println("------------------------------------------");
}
public static void main(String[] args)
{
ArrayList sampleArrayList =new ArrayList(); // you can specify the object type

Integer intr = new Integer(729);
String str ="Bharat";
double dtr = 169.721;

printArrayList(sampleArrayList);

sampleArrayList.add(intr);
sampleArrayList.add(str);
sampleArrayList.add(dtr);

printArrayList(sampleArrayList);

Integer i5=new Integer(50);
sampleArrayList.add(3, i5); // using add(int index, object obj)

printArrayList(sampleArrayList);

sampleArrayList.remove(3); // using remove()

printArrayList(sampleArrayList);

Object a=sampleArrayList.clone(); // using clone

System.out.println("The clone is: " + a);

printArrayList(sampleArrayList);

// iteration using iterator
Iterator iter = sampleArrayList.iterator();
System.out.println("Using Iterator");
while (iter.hasNext())
{
System.out.println(iter.next());
}

// using for loop and indexes
System.out.println("Using for loop and index");
for (int i=0; i {
System.out.println(sampleArrayList.get(i));
}
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/ERJ_5mp35vg/13419

 
arraylist demo
Friday, 29 July 2011 05:31
package questions;

import java.util.*;
/**
* @author Bharat Verma
*/
public class ArrayListDemo
{
public static void printArrayList (ArrayList p_arraylist)
{
System.out.println("------------------------------------------");
System.out.println("Content of ArrayList : "+p_arraylist);
System.out.println("Size of ArrayList = "+p_arraylist.size());
System.out.println("------------------------------------------");
}
public static void main(String[] args)
{
ArrayList sampleArrayList =new ArrayList(); // you can specify the object type

Integer intr = new Integer(729);
String str ="Bharat";
double dtr = 169.721;

printArrayList(sampleArrayList);

sampleArrayList.add(intr);
sampleArrayList.add(str);
sampleArrayList.add(dtr);

printArrayList(sampleArrayList);

Integer i5=new Integer(50);
sampleArrayList.add(3, i5); // using add(int index, object obj)

printArrayList(sampleArrayList);

sampleArrayList.remove(3); // using remove()

printArrayList(sampleArrayList);

Object a=sampleArrayList.clone(); // using clone

System.out.println("The clone is: " + a);

printArrayList(sampleArrayList);

// iteration using iterator
Iterator iter = sampleArrayList.iterator();
System.out.println("Using Iterator");
while (iter.hasNext())
{
System.out.println(iter.next());
}

// using for loop and indexes
System.out.println("Using for loop and index");
for (int i=0; i {
System.out.println(sampleArrayList.get(i));
}
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/ZT0n9RBlH_k/13417

 
Código del servlet (proccesRequest)
Tuesday, 10 August 2010 05:18
// ...



protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();

ArrayList lista = new ArrayList();
Universidad u = new Universidad();

lista = u.allUniversities();

String xml="";

int i;

try {
//TODO output your page here

xml=xml + "";
for(i=0;i xml=xml +"";
xml=xml +""+lista.get(i).getNombre()+"";
xml=xml +""+lista.get(i).getLatitud()+"";
xml=xml +""+lista.get(i).getLongitud()+"";
xml=xml +""+lista.get(i).getImagen()+"";
xml=xml +"
";
}
xml=xml +"
";

out.write(xml);

/*for(ind=0;ind out.println("

"+lista.get(ind).getNombre()+ "-"+ lista.get(ind).getPais() +"

");
}*/

} finally {
out.close();
}
}


Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/dxSyWGPEqfk/12015

 


Taxonomy by Zaragoza Online