<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>arraylist &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/arraylist/</link>
	<description>Feed of posts on WordPress.com tagged "arraylist"</description>
	<pubDate>Sun, 06 Dec 2009 17:46:51 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Preparando Certamen 3 – Ejercicio 2 [POO - Java] PEF2501]]></title>
<link>http://estebanfuentealba.wordpress.com/2009/11/28/preparando-certamen-3-%e2%80%93-ejercicio-2-poo-java-pef2501/</link>
<pubDate>Sun, 29 Nov 2009 01:58:23 +0000</pubDate>
<dc:creator>estebanfuentealba</dc:creator>
<guid>http://estebanfuentealba.wordpress.com/2009/11/28/preparando-certamen-3-%e2%80%93-ejercicio-2-poo-java-pef2501/</guid>
<description><![CDATA[Otro Ejercicio de Java para practicar para el cetamen 3 de Programación Orientada a Objetos&#8230; S]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://estebanfuentealba.wordpress.com/files/2009/11/thumb-java-duke-guitar.png"><img src="http://estebanfuentealba.wordpress.com/files/2009/11/thumb-java-duke-guitar.png?w=150" alt="" title="thumb-java-duke-guitar" width="150" height="128" class="alignleft size-thumbnail wp-image-723" /></a>Otro Ejercicio de Java para practicar para el cetamen 3 de Programación Orientada a Objetos&#8230; Solo Tienen que hacer lo que les piden&#8230; Si no piden main y no piden testear la aplicación no lo hagan (Si les sobra tiempo pueden hacerlo).</p>
<p><strong>Enunciado</strong>:</p>
<div id="_mcePaste">Una biblioteca requiere de una aplicación que sea capaz de llevar</div>
<div id="_mcePaste">un registro de los alumnos de las carreras y los pedidos de libros</div>
<div id="_mcePaste">que  ellos  realizan.  Para    cubrir  este  requerimiento  se  ha  creado</div>
<div id="_mcePaste">un conjunto de clases, cuya especificación es la siguiente:</div>
<div id="_mcePaste"></div>
<div id="_mcePaste"><strong>CARRERA </strong></div>
<div id="_mcePaste"><em>ATRIBUTOS</em></div>
<div id="_mcePaste">  nombre: String</div>
<div id="_mcePaste">  duración: byte</div>
<div id="_mcePaste">  acreditada: boolean</div>
<div id="_mcePaste">  registroAlumnos:  HashMap&#60;Alumno&#62;  (considerar  el  RUT  del</div>
<div id="_mcePaste">alumno como clave primaria (key))</div>
<div id="_mcePaste"></div>
<div id="_mcePaste"><em>MÉTODOS </em></div>
<div id="_mcePaste">
<ul>
<li>  Constructor sin parámetros</li>
<li>  Constructor  con  parámetros  (que  reciba  todos  los  atributos,  obviando  los  alumnos,  que  deben  ser  ingresados posteriormente)</li>
<li>  Accesador para cada atributo</li>
<li>  Mutador para cada atributo</li>
<li>  Método de impresión</li>
<li>  Método  addAlumno  (que  reciba  un  objeto  del  tipo  Alumno  ya inicializado  y  que  valide  la  unicidad  de  registros  mediante un  mensaje  en  caso  de  que  el  alumno  a  ingresar  ya  se encuentre registrado).</li>
</ul>
</div>
<p><strong>ALUMNO </strong></p>
<p><em>ATRIBUTOS</em>:</p>
<p>RUT: String (máximo 10, los primeros 8 son números, luego el “-” y finalmente un número o una letra)<br />
  tipo:  int  (considerar  uso  de  las  siguientes  constantes<br />
Alumno.ADJUNTO:1,Alumno.REGULAR:2, Alumno.RETIRADO:3)<br />
  ciudad: String<br />
  prestamos: ArrayList&#60;Préstamo&#62;</p>
<p><em>MÉTODOS</em>:</p>
<ul>
<li>  Constructor sin parámetros</li>
<li>  Constructor con parámetros (obviando los préstamos, que deben ser generados posteriormente)</li>
<li>  Accesador para cada atributo</li>
<li>  Mutador para cada atributo</li>
<li>  Método de impresión</li>
<li>  Método  addPrestamo,  que  reciba  como  parámetro  un  objeto  del tipo Préstamo ya inicializado.</li>
<li>  Método booleano isResponsable, que devuelve true si los tres últimos  préstamos  han  sido  devueltos  en  la  fecha  que corresponde,  false  en  su  defecto,  o  si  no  existen  préstamos registrados.</li>
</ul>
<p><strong>PRÉSTAMO </strong></p>
<p><em>ATRIBUTOS</em>:</p>
<p>  fechaPréstamo: date<br />
  fechaDevolución:  date  (no  puede  ser  inferior  a  la  fecha  de<br />
préstamo).<br />
  libro: String<br />
  atrasado: boolean</p>
<p><em>MÉTODOS</em>:</p>
<ul>
<li>  Constructor sin parámetros</li>
<li>  Constructor  con  parámetros  (que  reciba  todos  los  atributos, siendo atrasado: false)</li>
<li>  Accesador para cada atributo</li>
<li>  Mutador para cada atributo, excepto para el caso del atributo atrasado.</li>
<li>  Método de impresión</li>
<li>  Método  devolverLibro()  que  recibe  la  fecha  efectiva  de  la devolución  y  si  es  mayor  a  la  fecha  en  la  que  debía  ser devuelto el libro entonces deja el atributo atrasado seteado en true.</li>
</ul>
<p>Todas  las  reglas  de  negocio  deben  controlarse  con<br />
Excepciones.(Considerar  lanzar  objetos  Exception  para  el  tipo<br />
numérico  y  para  el  tipo  String  por  separado,  explicando  en  el<br />
mensaje la regla de negocio no cumplida).</p>
<p>&#160;</p>
<p><strong>Descarga Código de fuente</strong>:<br />
<a href="http://estebanfuentealba.net/ayudantia/PreparandoCertamen3EjercicioDos.rar">http://estebanfuentealba.net/ayudantia/PreparandoCertamen3EjercicioDos.rar</a></p>
<p>PD: Si quieren Testear El programa aqui les dejo un Main</p>
<pre class="brush: java;">
/**
 * @(#)EjercicioDos.java
 *
 * EjercicioDos application
 *
 * @author Esteban Fuentealba
 * @version 1.00 2009/11/28
 */
import cl.duoc.pef.ejerciciodos.entidades.*;
import cl.duoc.pef.ejerciciodos.exception.*;
import java.util.*;
public class EjercicioDos {

    public static void main(String[] args) {
    	try {
	    	Carrera c = new Carrera(&#34;Informatica&#34;,(byte)4,true);

	    	Alumno alumnoA = new Alumno(&#34;11111111-1&#34;,Alumno.REGULAR,&#34;Concepcion&#34;);
	    		Prestamo prestamoA = new Prestamo(new Date(2009,6,20),new Date(2009,6,25),&#34;POO Avanzada&#34;);
	    		Prestamo prestamoB = new Prestamo(new Date(2009,7,20),new Date(2009,8,25),&#34;Programacion para Principiantes&#34;);
	    		Prestamo prestamoC = new Prestamo(new Date(2009,9,20),new Date(2009,9,25),&#34;Como  salir de la Depresión&#34;);
	    	alumnoA.addPrestamo(prestamoA);
	    	alumnoA.addPrestamo(prestamoB);
	    	alumnoA.addPrestamo(prestamoC);

	    	Alumno alumnoB = new Alumno(&#34;22222222-2&#34;,Alumno.ADJUNTO,&#34;Concepcion&#34;);
	    		Prestamo prestamoD = new Prestamo(new Date(2009,7,20),new Date(2009,11,25),&#34;Revista caras&#34;);
	    	alumnoB.addPrestamo(prestamoD);
	    	Alumno alumnoC = new Alumno(&#34;33333333-3&#34;,Alumno.REGULAR,&#34;Concepcion&#34;);
	    	Alumno alumnoD = new Alumno(&#34;44444444-4&#34;,Alumno.RETIRADO,&#34;Santiago&#34;);

	    	c.addAlumno(alumnoA);
	    	c.addAlumno(alumnoB);
	    	c.addAlumno(alumnoC);
	    	c.addAlumno(alumnoD);

	    	c.imprimir();
	    	prestamoB.devolverLibro(new Date(2010,0,0));
	    	System.out.println(&#34;Responsable: &#34;+alumnoA.isResponsable());
    	} catch(NumberException exA) {
    		System.out.println(exA.getMessage());
    	} catch(StringException exB) {
    		System.out.println(exB.getMessage());
    	} catch(Exception exC) {
    		System.out.println(exC.getMessage());
    	}
   	}
}
</pre>
<p>Saludos!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java - ¿Qué uso, Array o List?]]></title>
<link>http://cirovladimir.wordpress.com/2009/10/29/java-%c2%bfque-uso-array-o-list/</link>
<pubDate>Thu, 29 Oct 2009 18:38:43 +0000</pubDate>
<dc:creator>cirovladimir</dc:creator>
<guid>http://cirovladimir.wordpress.com/2009/10/29/java-%c2%bfque-uso-array-o-list/</guid>
<description><![CDATA[Dentro de nuestros programas siempre habrá algun pedazo de código donde utilicemos arreglos. Mientra]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img src="http://cirovladimir.wordpress.com/files/2009/10/screenshot5.png" alt="ArrayVSList" title="ArrayVSList" width="150" height="154" class="alignnone size-full wp-image-308" /><br />
Dentro de nuestros programas siempre habrá algun pedazo de código donde utilicemos arreglos.<br />
Mientras implementaba unos métodos para insertar y eliminar registros de una clase, noté que en algunos había utilizado <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html" target="_blank">Arrays</a> y en otros <a href="http://www.j2ee.me/javase/6/docs/api/java/util/List.html" target="_blank">Lists</a>. Por ello decidí buscar que es lo que recomendaban otros programadores al respecto, fue así como encontré <a href="http://stackoverflow.com/questions/716597/array-or-list-in-java-which-is-faster" target="_blank">este artículo</a>.</p>
<p>Finalmente quede convencido de utilizar Lists debido a la <strong>flexibilidad</strong> que ofrecen.</p>
<p>Ejemplo:</p>
<pre class="brush: java;">
public static void insert(List&#60;Dato&#62; datos) {
  //... configuracion de conexion
  for(Dato dato:datos){
	db.executeUpdate(&#34;insert into datos(desc,cantidad) values(:desc,:cantidad)&#34;,
	new Object[]{dato.getDescripcion(),dato.getCantidad()});
  }
}
</pre>
<p><strong>VS.</strong></p>
<pre class="brush: java;">
public static void insert(Dato[] datos) {
  //... configuracion de conexion
  for(Dato dato:datos){
	db.executeUpdate(&#34;insert into datos(desc,cantidad) values(:desc,:cantidad)&#34;,
	new Object[]{dato.getDescripcion(),dato.getCantidad()});
  }
}
</pre>
<p>Como puedes observar, es prácticamente lo mismo, la diferencia es que al invocar el primer método puedes pasar como párametro un <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html" target="_blank">ArrayList</a>, <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html" target="_blank">LinkedList</a>, <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html" target="_blank">Vector</a> o tu propia clase que implemente la interfaz <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html" target="_blank">List</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .<br />
<a href="http://es.wikipedia.org/wiki/Byte" target="_blank"><br />
byte!</a></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=8f838877-dace-8320-8c55-552e2426734b" alt="" /></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Split string to ArrayList]]></title>
<link>http://stareat.wordpress.com/2009/09/14/split-string-to-arraylist/</link>
<pubDate>Mon, 14 Sep 2009 12:00:00 +0000</pubDate>
<dc:creator>stareat</dc:creator>
<guid>http://stareat.wordpress.com/2009/09/14/split-string-to-arraylist/</guid>
<description><![CDATA[Dim strStringToSplit As String = "1;2;3;4;5;6" Dim alArrayList As New ArrayList() alArrayList.AddRan]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><code></p>
<pre>
Dim strStringToSplit As String = "1;2;3;4;5;6"
Dim alArrayList As New ArrayList()
alArrayList.AddRange(strStringToSplit.Split(";"))
</pre>
<p></code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Knowledge Bank - 1]]></title>
<link>http://meghsoft.wordpress.com/2009/09/13/java-knowledge-bank-1/</link>
<pubDate>Sun, 13 Sep 2009 17:46:43 +0000</pubDate>
<dc:creator>meghsoft</dc:creator>
<guid>http://meghsoft.wordpress.com/2009/09/13/java-knowledge-bank-1/</guid>
<description><![CDATA[Q : Give a few reasons for using Java? A : Java is a fun language. Let’s look at some of the reasons]]></description>
<content:encoded><![CDATA[Q : Give a few reasons for using Java? A : Java is a fun language. Let’s look at some of the reasons]]></content:encoded>
</item>
<item>
<title><![CDATA[Remove matching items from ArrayList]]></title>
<link>http://stareat.wordpress.com/2009/09/08/remove-matching-items-from-arraylist/</link>
<pubDate>Tue, 08 Sep 2009 17:34:27 +0000</pubDate>
<dc:creator>stareat</dc:creator>
<guid>http://stareat.wordpress.com/2009/09/08/remove-matching-items-from-arraylist/</guid>
<description><![CDATA[Compare two ArrayLists and remove all matches. I use this for example to remove stop words from sear]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Compare two ArrayLists and remove all matches. I use this for example to remove stop words from search phrases or when i generate keywords programmatically!</p>
<p />
<code></p>
<pre>
Public Function RemoveMatches(ByVal alOriginal As ArrayList, ByVal alMatches As ArrayList) As ArrayList
    Dim alArrayList As New ArrayList

    For Each objObject As Object In alOriginal
        If Not alMatches.Contains(objObject.ToString.ToLower) Then
            alArrayList.Add(objObject)
        End If
    Next

    alOriginal.Clear()
    alMatches.Clear()

    alArrayList.TrimToSize()
    Return alArrayList
End Function
</pre>
<p></code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Remove duplicate items from ArrayList]]></title>
<link>http://stareat.wordpress.com/2009/09/04/remove-duplicate-items-from-arraylist/</link>
<pubDate>Fri, 04 Sep 2009 13:21:15 +0000</pubDate>
<dc:creator>stareat</dc:creator>
<guid>http://stareat.wordpress.com/2009/09/04/remove-duplicate-items-from-arraylist/</guid>
<description><![CDATA[Public Function RemoveDuplicate(ByVal alDuplicate As ArrayList) As ArrayList Dim alArrayList As New ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><code></p>
<pre>
Public Function RemoveDuplicate(ByVal alDuplicate As ArrayList) As ArrayList
    Dim alArrayList As New ArrayList
    For Each objObject As Object In alDuplicate
        If Not alArrayList.Contains(objObject) Then
            alArrayList.Add(objObject)
        End If
    Next
    alDuplicate.Clear()

    alArrayList.TrimToSize()
    Return alArrayList
End Function
</pre>
<p></code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[basic of C# (part 16)]]></title>
<link>http://sevenlamp.wordpress.com/2009/08/29/collection/</link>
<pubDate>Sat, 29 Aug 2009 07:37:17 +0000</pubDate>
<dc:creator>sevenlamp</dc:creator>
<guid>http://sevenlamp.wordpress.com/2009/08/29/collection/</guid>
<description><![CDATA[ကြၽန္ေတာ္တို႔ array ေတြ ေၾကျငာတဲ႔ အခါမွာ integer array ေၾကျငာရင္ integer ပဲ သိမ္းလို႔ ရပါမယ္။ string]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">ကြၽန္ေတာ္တို႔ array ေတြ ေၾကျငာတဲ႔ အခါမွာ integer array ေၾကျငာရင္ integer ပဲ သိမ္းလို႔ ရပါမယ္။ string array ဆိုရင္လည္း string ေတြပဲ သိမ္းမွာေပါ့။ ဒီလိုမဟုတ္ပဲ ကိုယ္ၾကိဳက္တဲ႔ data type ကို သိမ္းလို႔ ရခ်င္ရင္ေတာ့ object array ေဆာက္ေပးရပါတယ္။</p>
<div style="background-color:lightgray;padding:5px;">
<pre>object[] arr = new object[3];
arr[0] = 1;
arr[1] = 2.2;
arr[2] = "abcdefg";</pre>
</div>
<p style="text-align:justify;">အခုထိ ကြၽန္ေတာ္တို႔ သံုးခဲ႔တဲ႔ array ေတြရဲ႕ size ဟာ static size ျဖစ္ပါတယ္။ ကြၽန္ေတာ္တို႔ array ကို ၃ ခန္းေၾကျငာလိုက္ရင္ ၃ ခန္းထက္ပိုျပီး တန္ဖိုးထည့္လို႔ မရပါဘူး။ ကြၽန္ေတာ္တို႔ သံုးမယ့္ array ရဲ႕ size ကို dynamic size အျဖစ္သံုးခ်င္တယ္ ဆိုရင္ေတာ့ သီးျခားအေနနဲ႔ collection class ေတြကို သံုးၾကရမွာပါ။ ပထမဆံုးအေနနဲ႔ ArrayList Class အေၾကာင္း စေျပာပါ့မယ္။<br />
<strong><span style="color:#ff00ff;">ArrayList Class</span></strong> က array တစ္ခုလိုမ်ိဳး အလုပ္လုပ္ေပးပါတယ္။ သူက variant size ပါ။ စေၾကျငာခ်င္းခ်င္းမွာ ArrayList ရဲ႕ capacity က ၄ ခန္းယူထားေပးပါတယ္။ ကြၽန္ေတာ္တို႔ တန္ဖိုးထည့္ရင္းနဲ႔ ၄ခန္းျပည့္ျပီးလို႔ ေနာက္ထပ္ထပ္ထည့္တာနဲ႔ capacity က ၈ခန္းျဖစ္သြားမွာပါ။ ကိုယ္တကယ္ တန္ဖိုးထည့္ထားတဲ႔ အေရအတြက္ကိုေတာ့ count ဆိုတဲ႔ property ကေန ျပန္သိနိုင္ပါတယ္။ ArrayList က zero base index ျဖစ္ျပီးေတာ့ သူ႔ရဲ႕ index က integer type ပါ။ ArrayList ကလည္း object type လက္ခံတာျဖစ္တဲ႔ အတြက္ ကြၽန္ေတာ္တို႔ ၾကိဳက္တဲ႔ type ထည့္ေပးခြင့္ရွိပါတယ္။ example ေလးၾကည့္ရေအာင္။</p>
<div style="background-color:lightgray;padding:5px;">
<pre>using System;
using System.Collections;

class arraylistTest
{
    static void Main()
    {
        object[] arr = new object[3];
        arr[0] = 1;
        arr[1] = 2.2;
        arr[2] = "abcdefg";

        ArrayList ar = new ArrayList();
        ar.Add(1);
        ar.Add(9.456);
        ar.Add("ABC");
        ar.Add('Z');
        ar.Add(new arraylistTest());

        for (int i = 0; i &#60; ar.Count; i++)
        {
            Console.WriteLine("{0}\t( {1} )", ar[i], ar[i].GetType());
        }
        Console.WriteLine("\nActual Size of your Array : " + ar.Count);
        Console.WriteLine("Total Capacity of your Array : " + ar.Capacity);
        Console.Read();
    }
}</pre>
</div>
<p style="text-align:justify;"><span style="color:#ff00ff;"><strong>Hashtable Class</strong></span><br />
Hashtable class ထဲမွာ key/value တြဲ႕ data ေတြ လက္ခံပါတယ္။ key/value အတြဲလိုက္ကို DictionaryEntry လို႔ေခၚပါေသးတယ္။ ArrayList မွာ ကြၽန္ေတာ္တို႔ index ကို integer type သံုးပါတယ္။ Hashtable မွာေတာ့ index ေထာက္ဖို႔အတြက္ key ကိုသံုးပါတယ္။ သူကလည္း object type ပါ၊ ဒါေၾကာင့္ ကြၽန္ေတာ္တို႔ ၾကိဳ႔က္တဲ႔ type နဲ႔ index ေထာက္လို႔ ရပါတယ္။ သိမ္းမယ့္ data ေတြကိုေတာ့ value အပိုင္းမွာ သိမ္းရပါတယ္။ သူလည္း object type ပါပဲ။ Hashtable ကလည္း ArrayList လိုပဲ size ကို dynamically increment လုပ္လို႔ ရပါတယ္။ Example ေလးၾကည့္ရေအာင္။</p>
<div style="background-color:lightgray;padding:5px;">
<pre>using System;
using System.Collections;
class arraylistTest
{
    static void Main()
    {
        Hashtable ht = new Hashtable();
        ht.Add("Name", "Sevenlamp");
        ht.Add("Address", "Yangon");
        ht.Add("Age", 28);

        foreach (DictionaryEntry de in ht)
        {
            Console.WriteLine("{0}\t\t: \t {1} ", de.Key, de.Value);
        }
        Console.WriteLine("\nThere are {0} element/s in your Hashtable Array", ht.Count);
        Console.Read();
    }
}</pre>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Converter Array para Vetor!]]></title>
<link>http://codeerror.wordpress.com/2009/08/19/converter-array-para-vetor/</link>
<pubDate>Wed, 19 Aug 2009 23:52:44 +0000</pubDate>
<dc:creator>codeerror</dc:creator>
<guid>http://codeerror.wordpress.com/2009/08/19/converter-array-para-vetor/</guid>
<description><![CDATA[Sim isso mesmo, no lugar de &#8220;progredir&#8221; vamos &#8220;regredir&#8221; um pouco, por que n]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Sim isso mesmo, no lugar de <em><strong>&#8220;progredir&#8221;</strong></em> vamos<em><strong> &#8220;regredir&#8221;</strong></em> um pouco, por que não é sempre que podemos trabalhar com as melhores condições possíveis, muitas vezes também precisamos colocar a mão na sujeira e editar algum código um tanto quanto ultrapassado, que <strong><span style="color:#ff0000;">ainda</span></strong> trabalha com vetores.</p>
<p>Se você já trabalhou com vetores, mesmo que apenas na faculdade, deve saber que com eles não conseguimos manipular os dados <strong>incluindo </strong>ou <strong>excluindo</strong>, só conseguimos criar (e destruir).</p>
<blockquote><p>Ex.: String[] meuVetor = <strong><span style="color:#800080;">new </span></strong>String[] {<span style="color:#0000ff;">&#8220;A&#8221;</span>,<span style="color:#0000ff;"> &#8220;B&#8221;</span>,<span style="color:#0000ff;"> &#8220;C&#8221;</span>, <span style="color:#0000ff;">&#8220;D&#8221;</span>, <span style="color:#0000ff;">&#8220;E&#8221;</span>};</p></blockquote>
<p>Neste exemplo, criamos um vetor com <span style="color:#993300;">5</span> posições, até aqui tudo bem, podemos solicitar cada posição do vetor com a chamada <span style="color:#993300;">meuVetor[<strong>n</strong>]</span>,  trocando <strong>&#8220;n&#8221;</strong> pela posição do vetor, é claro, no nosso caso de<span style="color:#993300;"> 0</span> a <span style="color:#993300;">4</span>.</p>
<p>Mas e se for necessário, em tempo de execução, adicionar algum valor ao vetor? Não é possível fazer um <em><span style="color:#993300;">&#8220;</span><span style="color:#993300;">meuVetor.add()</span><span style="color:#993300;">&#8220;</span></em>, então como fazer?<br />
Simples! Basta trabalhar com Array, List ou Collection e <strong>jogar esse vetor no lixo</strong>!<br />
Mas e se a aplicação nos forçar a trabalhar com vetor, caso contrário seria necessário refazer todo o código?</p>
<p>Simples! Basta trabalhar com Array e converter para Vetor!<br />
Como?</p>
<p>Vejamos o exemplo, em javanês:</p>
<blockquote><p>ArrayList&#60;String&#62; <span style="color:#3366ff;">meuArray </span>= <strong><span style="color:#800080;">new </span></strong>ArrayList&#60;String&#62;();<br />
String[] <span style="color:#3366ff;">meuVetor </span>= <strong><span style="color:#800080;">null</span></strong>;</p>
<p><span style="color:#800080;"><strong>for</strong></span>(<span style="color:#800080;"><strong>int </strong></span><span style="color:#000000;">i</span> = 0; <span style="color:#000000;">i</span> &#60; 10; <span style="color:#000000;">i</span>++){<br />
<span style="color:#3366ff;">meuArray</span>.add(<em><span style="color:#0000ff;">&#8220;POSICAO: &#8220;</span></em> + i);<br />
}</p>
<p><span style="color:#3366ff;">meuVetor </span>= <span style="color:#3366ff;">meuArray</span>.toArray(<span style="color:#800080;"><strong>new </strong></span>String[<span style="color:#3366ff;">meuArray</span>.size()]);</p></blockquote>
<p><span style="text-decoration:underline;"><strong>Explicando!</strong></span></p>
<p>A primeira e segunda linha não tem segredo, ali estão sendo criadas nossas variáveis base, um <strong>ArrayList meuArray</strong> e um vetor <strong>String[] meuVetor</strong>.<br />
O laço &#8220;for&#8221; também não tem muita complicação, de 0 até 9 ele está inserindo valores no Array.</p>
<p>Na ultima linha que a mágica acontece, vamos por partes:</p>
<p>Primeiro, estamos vazendo<span style="color:#ff0000;"><strong> meuVetor = meuArray.toArray()</strong></span> este método (toArray) é da própria linguagem Java, e serve exatamente para isso que precisamos, ele prepara um Array para ser convertido em Vetor, mas este método sozinho não faz muita coisa, então precisamos informar o tipo de vetor que estamos querendo, no caso é um vetor de String, então dentro do toArray basta informar <span style="color:#ff0000;"><strong>new String[n].</strong></span> Mas que <em><strong>&#8220;n&#8221;</strong></em>? para criar um Vetor, precisamos informar a quantidade de posições que ele terá, e para conseguir esta façanha, basta invocar o método <span style="color:#ff0000;"><strong>size()</strong></span> do <span style="color:#ff0000;"><strong>meu </strong></span><span style="color:#ff0000;"><strong>Array</strong></span>, que devolve o tamanho do array, justamente o que precisamos para iniciar o Vetor!</p>
<p>Simples né?!<br />
Boa sorte!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[UIMA - WriteMalletInput.java allocates large memory issue]]></title>
<link>http://billhao.wordpress.com/2009/06/10/writemalletinput-java-allocates-large-memory-issue/</link>
<pubDate>Wed, 10 Jun 2009 21:20:36 +0000</pubDate>
<dc:creator>Hao</dc:creator>
<guid>http://billhao.wordpress.com/2009/06/10/writemalletinput-java-allocates-large-memory-issue/</guid>
<description><![CDATA[When I was training a model using 30 documents, the Java program allocated more than 700Mb memory an]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>When I was training a model using 30 documents, the Java program allocated more than 700Mb memory and started to cause many memory page file swaps on my laptop which made the processing really slow and the computer almost not responding. Memory configurations of the Java program and my laptop are shown below.</p>
<blockquote><p>Java program: -Xmx1G</p>
<p>Computer: 1.5Gb physical memory, 4.4Gb physical memory plus virtual memory (Windows XP Sp2)</p></blockquote>
<p>After profiling with Yourkit 8.08, I found that a large ArrayList with 16384 items allocated and HashMaps (512 allocated items each) in that ArrayList were where most memory was consumed. The initial size of the ArrayList was set to 16384 but it had only about 5000 items after processing the 30 documents. The initial size of Hashmaps was set to 512 but many of them contained only a hundred of items. Similar situations were also found in FeatureRecord and DirFileReader. I have changed them to use a smaller initial size or the predefined size. Even if there will be a lot more documents to be processed in the future, these code has to be rewrite to work efficiently.</p>
<p>Related source files: WriteMalletInput.java, FeatureRecord.java, DirFileReader.java</p>
<p>Memory snapshot from Yourkit can ben found in Main_TrainingDescriptor.xml-2009-06-10-low-memory.rar</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[manually add rows to datagridview]]></title>
<link>http://ttprog.wordpress.com/2009/05/12/manually-add-row-to-datagridview/</link>
<pubDate>Tue, 12 May 2009 11:40:11 +0000</pubDate>
<dc:creator>Tomas Thalmann</dc:creator>
<guid>http://ttprog.wordpress.com/2009/05/12/manually-add-row-to-datagridview/</guid>
<description><![CDATA[Filling a gridview with your appropriate data can be done through several ways (or is approach the b]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Filling a gridview with your appropriate data can be done through several ways (or is approach the better word?). the one which i think is the easiest is the following.</p>
<p>The case: I&#8217;m viewing an arraylist of custom objects in my datagridview, obj is the one i want to add and represents a row of my gridview.</p>
<p>So the gridview has one function that allows me to add rows manually:</p>
<div style="border:1px solid #cccccc;padding:10px;">
<pre style="font-size:small;font-family:Consolas, 'Courier New', Courier, Monospace;">
dgGridview.Rows.Add(<span style="color:#000080;">this.</span>getValuesToAdd(obj));</pre>
</div>
<p></p>
<p><!--more--><br />
This functions takes an object array, so I wrote a simple function, that takes my object and returns an object array:</p>
<div style="border:1px solid #cccccc;padding:10px;">
<pre style="font-size:small;font-family:Consolas, 'Courier New', Courier, Monospace;">
<span style="color:#000080;">private</span> <span style="color:#000080;">object</span>[] getValuesToAdd(Object o)
{
    CustomObject co = (CustomObject)o;
    List&#60;<span style="color:#000080;">object</span>&#62; l = <span style="color:#000080;">new</span> List&#60;<span style="color:#000080;">object</span>&#62;(5);

    l.Add(co.name);
    l.Add(co.date);
    l.Add(co.xvalue);
    l.Add(co.yvalue);
    l.Add(co.zvalue);

    <span style="color:#000080;">return</span> l.ToArray();
}</pre>
</div>
<p></p>
<p>Alternatively you can use a List object to ease the handling:</p>
<div style="border:1px solid #cccccc;padding:10px;">
<pre style="font-size:small;font-family:Consolas, 'Courier New', Courier, Monospace;">
<span style="color:#000080;">private</span> <span style="color:#000080;">object</span>[] getValuesToAdd(Object o)
{
    CustomObject co = (CustomObject)o;
    <span style="color:#000080;">object</span>[] objects = { co.name, co.date, co.xvalue, co.yvalue, co.zvalue };

    <span style="color:#000080;">return</span> objects
}</pre>
</div>
<p></p>
<p>To use this codesnippet you have to define the columns in the properties page of the datagridview, or set them by code,&#8230; but what for do we have visual studio?</p>
<p>That&#8217;s all and it&#8217;s working fine,but i think, the best way (what i think) is to use a dataset, populate it with the data, and set the datasource of the gridview to the dataset. When adding rows dynamically (e.g. on button click) it might work to add a new row to the dataset and rebind the datasource? </p>
<p>But I&#8217;m not very familiar with datasets and when starting the project i didn&#8217;t even know, that i&#8217;ll use a gridview&#8230;<br />
so it&#8217;s possibly not the best solution, but &#8216;all roads lead to rome&#8217; in softwaredevelopement. I know this should not be the attitude of a programmer, but real life is hard. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[sort arraylist with custom objects]]></title>
<link>http://ttprog.wordpress.com/2009/05/11/sort-arraylist-with-custom-objects/</link>
<pubDate>Mon, 11 May 2009 11:04:16 +0000</pubDate>
<dc:creator>Tomas Thalmann</dc:creator>
<guid>http://ttprog.wordpress.com/2009/05/11/sort-arraylist-with-custom-objects/</guid>
<description><![CDATA[Today I needed to sort an ArrayList with custom objects. I googled a short time and found a bunch of]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Today I needed to sort an ArrayList with custom objects. I googled a short time and found a bunch of solutions, like using a LinkedList instead of an ArrayList, or using IComparor. They all seemed pretty good, but a little too much work <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . So I ended up with IComparable, which I think is the easiest and fastest way.</p>
<p>It comes with
<div style="border:1px solid #cccccc;padding:10px;">
<pre style="font-size:small;font-family:Consolas, 'Courier New', Courier, Monospace;">al.Sort();</pre>
</div>
<p></p>
<p>which uses the IComparable implementation of each element, to sort my arraylist. If your it contains only basic data types, that&#8217;s all you need to sort your ArrayList. So far, so good, but my list contains objects from my custom class.</p>
<p>So I needed my class to implement IComparable, to tell the hardworking little man inside my notebook which field to use when comparing an object with another.</p>
<div style="border:1px solid #cccccc;padding:10px;">
<pre style="font-size:small;font-family:Consolas, 'Courier New', Courier, Monospace;">
<span style="color:#000080;">class</span> myClass : IComparable
{
    <span style="color:#000080;">private</span> DateTime dt;
    <span style="color:#000080;">private</span> <span style="color:#000080;">double</span> v1;
    <span style="color:#000080;">private</span> <span style="color:#000080;">double</span> v2;

    <span style="color:#008000;">//code omited</span>

    <span style="color:#000080;">public</span> <span style="color:#000080;">int</span> CompareTo(<span style="color:#000080;">object</span> obj)
    {
        <span style="color:#000080;">if</span> (obj <span style="color:#000080;">is</span> myClass)
        {
            myClass temp = (myClass)obj;
            <span style="color:#000080;">return</span> <span style="color:#000080;">this</span>.Date.CompareTo(temp.Date);
        }
        <span style="color:#000080;">else</span>
        {
            <span style="color:#000080;">throw</span> <span style="color:#000080;">new</span> ArgumentException(<span style="color:#800000;">"object is not from type myClass"</span>);
        }
    }
}</pre>
</div>
<p></p>
<p>Theres a full example on msdn: <a href="http://msdn.microsoft.com/en-us/library/system.icomparable.aspx">http://msdn.microsoft.com/en-us/library/system.icomparable.aspx</a></p>
<p>That&#8217;s it, within half a minute everything works fine, without the need of writing a Comparer or other exotic code. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Konvertera en arraylist to array]]></title>
<link>http://dodevunited.wordpress.com/2009/03/29/konvertera-en-arraylist-to-array/</link>
<pubDate>Sun, 29 Mar 2009 13:52:03 +0000</pubDate>
<dc:creator>JFR</dc:creator>
<guid>http://dodevunited.wordpress.com/2009/03/29/konvertera-en-arraylist-to-array/</guid>
<description><![CDATA[Stötte på detta som var lite annorlunda än vad jag trodde. Skapande av en array i .NET skapar jag so]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Stötte på detta som var lite annorlunda än vad jag trodde. Skapande av en array i .NET skapar jag som:</p>
<h4 class="beTitle"><strong><em>System.Array arrayName;</em></strong></h4>
<div id="msgcns!85AA51362C69BBDC!1367" class="bvMsg">
<div>Vilket gör att när man tex ska konvertera en arraylist till array så är det så enkelt som:</div>
<div> </div>
<div><strong><em>System.Array arrayName = arrayListName.ToArray(typeof(int));</em></strong></div>
<div><strong><em></em></strong> </div>
<div>Men då jag använde en annan killes .NET-dll (eller tjej) så helt plötsligt ville det programmet ha en array som <strong>int[] </strong>och inte vanlig array. Hur lösa det tänker man då, inte fan kunde man trycka in ovanstående array utan fel;</div>
<div> </div>
<div><strong><em>funktionsnamn(ref int[])</em></strong></div>
<div><strong><em></em></strong> </div>
<div>Fick istället skapa en sådan här array enligt:</div>
<div> </div>
<div><strong><em>int[] arrayName;</em></strong></div>
<div><strong><em></em></strong> </div>
<div>och konverteringen:</div>
<div><strong><em></em></strong> </div>
<div><strong><em>arrayName = (int[])arrayListName.ToArray(typeof(int));</em></strong></div>
<div><strong><em></em></strong> </div>
<div>Varför inte bara använda det från början tänker alla då, jo därför att en tredje persons dll ville ha en arraylist och det skulle vara samma lista. Så det blev mellanmjölk för att bland lättmjölk och standardmjölk&#8230;</div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Vector vs ArrayList]]></title>
<link>http://manikandanmv.wordpress.com/2009/03/21/vector-vs-arraylist/</link>
<pubDate>Sat, 21 Mar 2009 09:37:14 +0000</pubDate>
<dc:creator>manikandanmv</dc:creator>
<guid>http://manikandanmv.wordpress.com/2009/03/21/vector-vs-arraylist/</guid>
<description><![CDATA[Almost all basic java programmers have this doubt in his mind which one is best to use either Vector]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Almost all basic java programmers have this doubt in his mind which one is best to use either <strong>Vector </strong>or <strong>ArrayList</strong>, <strong>Hashtable </strong>or <strong>HashMap</strong>. I don&#8217;t want to deviate this topic by evaluating the time required for insertions/deletions/modifications of data in each class instances. Just want to convey a main difference that&#8217;s enough for developers to use these classes in a better way.  In Java, both the classes are similar from an API perspective but there has to be some differences. Let&#8217;s see below.</p>
<p><strong>Vector</strong></p>
<ul>
<li> Vector is <strong>thread safe</strong>, because vector objects are synchronized which means you can access vector objects from any number of threads at the same time without affecting its data.</li>
<li>Due to the above reason, In performance wise Vector is <strong>slightly slower</strong> than ArrayList</li>
</ul>
<p><strong>ArrayList</strong></p>
<ul>
<li> ArrayList is just opposite of Vector class. Its <strong>not thread safe</strong>, suppose if you are using ArrayList instances in multiple threads surely which leads to create some problems while accessing.</li>
<li>ArrayList comes from <strong>Collection Framework</strong> family. So its easy to developers to convert in to any other datastructure formats.</li>
</ul>
<p>According to me, when you are going to write code without threads it would be better to use ArrayList instead of Vector. Because this will improve your code performance. Anyway based on your requirements you can choose either Vector or ArrayList.</p>
<p>If you want to use/access ArrayList objects concurrently without affecting its data, its possible. In Java, an API is available to achieve this.</p>
<blockquote><p>
List asyncList = Collections.synchronizedList(new ArrayList());
</p></blockquote>
<p>Like Vector vs ArrayList, the same differences are applies to Hashtable vs HashMap respectively</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[IN operator in iBatis]]></title>
<link>http://deviltechie.wordpress.com/2009/03/12/in-operator-in-ibatis/</link>
<pubDate>Thu, 12 Mar 2009 12:17:14 +0000</pubDate>
<dc:creator>Anoop</dc:creator>
<guid>http://deviltechie.wordpress.com/2009/03/12/in-operator-in-ibatis/</guid>
<description><![CDATA[Another confusion will occur while working with iBatis , when we need to do something like where id ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Another confusion will occur while working with iBatis , when we need to do something like</p>
<blockquote><p>where id in (100,101,102)</p></blockquote>
<p>We can simply do it as like this.</p>
<blockquote><p>where r.status = &#8216;A&#8217;<br />
&#60;dynamic &#62;<br />
&#60;isNotNull property=&#8221;Clients&#8221;&#62;<br />
and c.id<br />
&#60;iterate property=&#8221;Clients&#8221; open=&#8221;IN (&#8221; close=&#8221;)&#8221; conjunction=&#8221;,&#8221;&#62;<br />
#Clients[]#<br />
&#60;/iterate&#62;<br />
&#60;/isNotNull&#62;<br />
&#60;isNotNull property=&#8221;SMT&#8221;&#62;<br />
and t.smt_id<br />
&#60;iterate property=&#8221;SMT&#8221; open=&#8221;IN (&#8221; close=&#8221;)&#8221; conjunction=&#8221;,&#8221;&#62;<br />
#SMT[]#<br />
&#60;/iterate&#62;<br />
&#60;/isNotNull&#62;<br />
&#60;/dynamic&#62;</p></blockquote>
<p>where SMT and Clients are lists, which can be any lists,  that I put into the parameter map(here am passing java.util.HashMap as parameter map).</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[A classe ArrayList - C#]]></title>
<link>http://alanrossi.wordpress.com/2009/03/04/a-classe-arraylist-c/</link>
<pubDate>Wed, 04 Mar 2009 16:16:16 +0000</pubDate>
<dc:creator>Alan Rossi</dc:creator>
<guid>http://alanrossi.wordpress.com/2009/03/04/a-classe-arraylist-c/</guid>
<description><![CDATA[A classe ArrayList do Framework .NET imita a funcionalidade dos arrays convencionais e permite o red]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>A classe ArrayList do Framework .NET imita a funcionalidade dos arrays convencionais e permite o redimensionamento dinâmico da coleção por meio dos métodos da classe. Em qualquer momento, uma ArrayList contém um certo número de elementos menos que ou igual à sua capacidade (o número de elementos atualmente reservador para a ArrayList).</p>
<p>Podemos manipular a capacidade de uma ArrayList por meio da propriedade Capacity. Se uma ArrayList precisa ser redimensionada, por padrão, sua Capacity é dobrada.</p>
<p>ArrayLists armazenam referências à objetos. Todas as classes .NET derivam da classe object. Isso quer dizer que uma ArrayList pode conter objetos de qualquer tipo. </p>
<p><strong>Exemplo de como criar um ArrayList de inteiros e percorrê-lo usando o laço foreach.</strong></p>
<p><em>static void Main(string[] args){</p>
<p>  // Cria o ArrayList<br />
  ArrayList lista = new ArrayList();</p>
<p>  // Adiciona 5 inteiros<br />
  lista.Add(30);<br />
  lista.Add(2);<br />
  lista.Add(98);<br />
  lista.Add(1);<br />
  lista.Add(7);</p>
<p>  // Percorre os elementos da ArrayList<br />
  foreach(int valor in lista)<br />
    Console.Write(&#8220;{0} &#8220;, valor);</p>
<p>  Console.WriteLine(&#8220;\n\nPressione uma  tecla para sair&#8230;&#8221;);<br />
  Console.ReadKey();<br />
}</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Converting ArrayList To Array]]></title>
<link>http://javacoders.wordpress.com/2009/03/03/converting-arraylist-to-array/</link>
<pubDate>Tue, 03 Mar 2009 05:54:27 +0000</pubDate>
<dc:creator>ihumanoid</dc:creator>
<guid>http://javacoders.wordpress.com/2009/03/03/converting-arraylist-to-array/</guid>
<description><![CDATA[The Important usage of showing an ArrayList as Array is when you used to pass arguments as arrays an]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The Important usage of showing an ArrayList as Array is when you used to pass arguments as arrays and not as ArrayList.</p>
<pre class="brush: java;">

import java.util.ArrayList;

public class ArrayListToArray
{
    public static void main(String[] args)
    {
        ArrayList al = new ArrayList();

        //Add Elements
        al.add(new Integer(1));
        al.add(new Integer(10));
        al.add(new Integer(21));

        //Show contents
        System.out.println(&quot;Contents of Arraylist : &quot; + al);

        //Get Array
        Object[] arr = al.toArray();

        //Print Array
        int sum = 0;
        for(Object x : arr)
        {
            System.out.println(x);
            sum += ((Integer)x).intValue(); //Converting object to int
        }

        System.out.println(&quot;Sum = &quot; + sum);
    }
}
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ArrayList]]></title>
<link>http://javacoders.wordpress.com/2009/03/03/arraylist/</link>
<pubDate>Tue, 03 Mar 2009 05:42:47 +0000</pubDate>
<dc:creator>ihumanoid</dc:creator>
<guid>http://javacoders.wordpress.com/2009/03/03/arraylist/</guid>
<description><![CDATA[An ArrayList is another collection implementation. import java.util.*; public class ArrayListDemo { ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>An ArrayList is another collection implementation.</p>
<pre class="brush: java;">

import java.util.*;

public class ArrayListDemo
{
    public static void main(String[] args)
    {
        ArrayList al = new ArrayList();
        System.out.println(&quot;Initial Size Of ArrayList : &quot; + al.size());

        //Add elements to array list
        al.add(&quot;i&quot;);
        al.add(&quot;h&quot;);
        al.add(&quot;u&quot;);
        al.add(&quot;m&quot;);
        al.add(&quot;a&quot;);
        al.add(&quot;n&quot;);
        al.add(&quot;o&quot;);
        al.add(&quot;i&quot;);
        al.add(&quot;d&quot;);
        al.add(&quot;.&quot;);
        al.add(&quot;s&quot;);

        System.out.println(&quot;Size of ArrayList after additions : &quot;+ al.size());

        //Contsnt of ArrayList
        System.out.println(&quot;Contents of ArrayList : &quot; + al);

        //Remove Elements From ArrayList
        al.remove(&quot;.&quot;);
        al.remove(6);

        //Contents of ArrayList after removal
        System.out.println(&quot;Size of arraylist after removal : &quot; + al.size());
        System.out.println(&quot;Contents After Removal : &quot; + al);
    }
}
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Converting ResultSet into ArrayList]]></title>
<link>http://anandmuranal.wordpress.com/2009/02/20/converting-resultset-into-arraylist/</link>
<pubDate>Fri, 20 Feb 2009 07:50:23 +0000</pubDate>
<dc:creator>Anand Muranal</dc:creator>
<guid>http://anandmuranal.wordpress.com/2009/02/20/converting-resultset-into-arraylist/</guid>
<description><![CDATA[public ArrayList resultSetToArrayList(ResultSet rs) throws SQLException{ ResultSetMetaData md = rs.g]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><blockquote><p>public ArrayList resultSetToArrayList(ResultSet rs) throws SQLException{<br />
ResultSetMetaData md = rs.getMetaData();<br />
int columns = md.getColumnCount();<br />
ArrayList results = new ArrayList();</p>
<p>while (rs.next()){<br />
HashMap row = new HashMap();<br />
results.add(row);<br />
for(int i=1; i&#60;=columns; i++){<br />
row.put(md.getColumnName(i),rs.getObject(i));<br />
}<br />
}<br />
return results;<br />
}</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Recent bits and bobs - Switch, Save/Load, For:each, Iterator]]></title>
<link>http://chilloxk.wordpress.com/2009/01/31/recent-bits-and-bobs-switch-saveload-foreach-iterator/</link>
<pubDate>Sat, 31 Jan 2009 00:49:39 +0000</pubDate>
<dc:creator>chilloxk</dc:creator>
<guid>http://chilloxk.wordpress.com/2009/01/31/recent-bits-and-bobs-switch-saveload-foreach-iterator/</guid>
<description><![CDATA[The lab for monday is almost entirely the same as the DVD labs. Here I&#8217;ll post some minor bits]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The lab for monday is almost entirely the same as the DVD labs. Here I&#8217;ll post some minor bits we went over in lectures which might help a bit.</p>
<p><strong>Switch Statements</strong></p>
<p>These are handy for checking specific things like numbers&#8217; equality. They are useful if you want to have menus and use numbers for imput and the like.</p>
<p>eg:</p>
<p>we have a menu that says &#8216;please enter a number to select an option&#8217;, which is stored in an int called choice:</p>
<p>println(&#8220;please enter a number to select an option: &#8220;);</p>
<p>int choice = readInt();</p>
<p>the syntac for switch is:</p>
<p>switch (expression){</p>
<p>case n:</p>
<p>method();</p>
<p>break;</p>
<p>case n+1:</p>
<p>method2();</p>
<p>break;</p>
<p>}</p>
<p>this checks if expression is equal to n, if not, n+1, and will keep going down the list. it will execute the methods inside the case: until it comes to break; which ends the statement.</p>
<p><strong>SAVE / LOAD<br />
</strong></p>
<p>as in the lectures:</p>
<p>save:</p>
<p>saveToFile(dvds, &#8220;DVDs.xml&#8221;);</p>
<p>in this case, what happens is the contents of dvds(which is an arrayList of type String) is saved in the file called DVDs.xml in the directory your project is saved in.</p>
<p>load:</p>
<p>dvds = (ArrayList&#60;String&#62;) readFromFile(&#8220;DVDs.xml&#8221;);</p>
<p>this overwrited the file dvds (which is an ArrayList&#60;String&#62;) with the contents of the file DVDs.xml in the project directory.</p>
<p><strong>FOR:EACH LOOP</strong></p>
<p>Watch out with these, in a for:each loop, you cycle through elements of an array, arraylist or whatever, but you cannot modify the contents of the thing you are cycling though. It actually gives you a copy of what is contained, not the file itself.</p>
<p>syntax:     for(type anyname: listname)</p>
<p>type: String, int, DVD, Song.</p>
<p>anyname: the name which you will refer to each element by.</p>
<p>listname: the exact name of the array/ArrayList.</p>
<p>eg:</p>
<p>public void listDVDs(){</p>
<p>for(String moo: dvds)</p>
<p>{    println(dvd);    }</p>
<p>}</p>
<p>This will pick the first element in the arrayList &#8216;dvds&#8217; (which holds String names), which shall be refered to as moo, and then execute whatever is inside the curly brackets. in this case it prints them out.</p>
<p>If it held DVD types, this would print the names of the dvds:</p>
<p>public void listDVDs(){</p>
<p>for(DVD moo: dvds)</p>
<p>{   print( moo.getTitle() );    }</p>
<p>}</p>
<p>Because we would get each DVD object stored in the arrayList, and all its methods inside it too, like a normal for loop.</p>
<p><strong>ITERATOR</strong></p>
<p>Don&#8217;t entirely know much about these, just that they are ways of cycling through and altering elements in lists/sets. Similar to a for-loop but with it&#8217;s own methods.</p>
<p>import the use of it by using: import java.util.Iterator;</p>
<p>we create it by the following: (not sure on the capital or small &#8216;i&#8217;/'I&#8217;)</p>
<p>Iterator&#60;Type&#62; iteratorname = collection.iterator();</p>
<p>eg: Iterator&#60;DVD&#62; it = dvds.iterator();</p>
<p>this creates an iterator which can cycle through DVD objects, we will call it &#8216;it&#8217;, and it will be attached to the dvds arrayList collection.</p>
<p>this iterator has its own methods;</p>
<p>hasNext() &#8211; which returns a true/false if there is another element in the list.</p>
<p>and next() &#8211; which gets the next element.</p>
<p>used generally (for the moment) like this:</p>
<p>while(it.hasNext() )</p>
<p>{ it.next(); }</p>
<p>to print the name of the DVDs:</p>
<p>while(it.hasNext() )</p>
<p>{ println(it.next().getTitle() ); }</p>
<p>Next: HashSets and HastMaps</p>
<p>specific questions to chilloxk[-at-]hotmail(-dot-).COM</p>
<p><strong><br />
</strong></p>
<p><strong><br />
</strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java 3: More on arrays and basic ArrayList]]></title>
<link>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylist/</link>
<pubDate>Mon, 26 Jan 2009 18:51:25 +0000</pubDate>
<dc:creator>chilloxk</dc:creator>
<guid>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylist/</guid>
<description><![CDATA[Smash. // (Some things needed for the assignment) if, for any reason,(hint) you need to access an ar]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Smash.</p>
<p>// (Some things needed for the assignment)</p>
<p>if, for any reason,(hint) you need to access an array outside of a<br />
class, you will need to create a method to access that method<br />
(basically, you will need 2: one method (a getter) that returns the<br />
full array, and another (another getter) that returns just the value<br />
of the array that you want.</p>
<p>This is slightly complicated, I didn&#8217;t cop it till Mairead answered an<br />
email I sent to her.</p>
<p>The reason you need to do this is simple:<br />
-you create the array as PRIVATE, therefore it cannot be accessed<br />
outside the CLASS it is created in.<br />
-this means that all the elements are also PRIVATE.</p>
<p>So to access them, you need something like:</p>
<p>// will return the entire array<br />
public String/int/double accessArray()<br />
{<br />
return String/int/double array[];<br />
}</p>
<p>// will return the contents of &#8216;i&#8217;<br />
public String/int/double accessArrayElement(int i)<br />
{<br />
return String/int/double array[i];<br />
}</p>
<p>ArrayLists are some job.</p>
<p>You can do the exact same stuff as arrays, storing data wise, but you<br />
don&#8217;t have to specify the size of the array initially.<br />
Better because:<br />
- save memory in the PC<br />
- can&#8217;t fill it</p>
<p>creation:</p>
<p>ArrayList&#60;String/TicketMachine/int/double&#62; smash = new</p>
<div class="msg">ArrayList&#60;String/TicketMachine/int/double&#62;;</p>
<p>this String/TicketMachine/int/double arraylist is created and referred<br />
to as smash.</p>
<p>again, it can only hold the above element^.</p>
<p>It differs to an array in some ways, namely;</p>
<p>arrays are added to by doing this:<br />
array[i] = x;<br />
that means x is added to index i of the array.</p>
<p>(will refer to the arraylist as smash)<br />
arraylists are added to by doing this:<br />
smash.add(x);<br />
this will add x to the arraylist smash&#8217;s NEXT FREE POSITION</p>
<p>to remove an element:<br />
smash.remove(i);<br />
this will remove the i&#8217;th element in the arraylist smash</p>
<p>the Length of the ArrayList is referred to as a method: length()</p>
<p>So if it&#8217;s 10 elements long, it&#8217;s labelled from 0 &#8211; 9.</p>
<p>to access data in the arraylist;</p>
<p>smash.get(i);</p>
<p>( the array equivalent is:<br />
array[i]; )</p>
<p>for instance, if I created an ArrayList that held a bank account</p>
<p>ArrayList&#60;BankAccount&#62; bacc = new ArrayList&#60;BankAccount&#62;;</p>
<p>add account:<br />
bacc.add(cust_1);</p>
<p>or remove account in position 0.<br />
bacc.remove(0);</p>
<p>or get the name of the person in that arrayList in position 0.</p>
<p>bacc.get(0).getName();</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
create a method that returns all the people&#8217;s names in the arrayList:</p>
<p>public String getTheNames()<br />
{<br />
String temp = &#8221; &#8220;; (make it an empty string)</p>
<p>for(int i = 0; i &#60; bacc.length(); i++)<br />
{<br />
temp  = &#8220;&#8221; + temp + bacc.get(i).getName() + &#8220;, &#8220;;<br />
}<br />
return temp;<br />
}</p>
<p>I think you have to have the &#8220;&#8221; which &#8216;tells&#8217; the compiler that it&#8217;s a<br />
string it&#8217;s adding to.<br />
If you&#8217;re not sure, google: string concatenation. prob better off doing that.</p>
<p>temp  = &#8220;&#8221; + temp + bacc.get(i).getName() + &#8220;, &#8220;;<br />
(line by line: )</p>
<p>&#8216; temp = &#8216; -&#62; if you dont know that this means at this stage&#8230; FUCK OFF. hah.</p>
<p>&#8216; &#8220;&#8221; &#8216; -&#62; this is just an empy String</p>
<p>&#8216; + temp &#8216; -&#62; adds temp to whats already in temp and what&#8217;s in &#8220;&#8221;</p>
<p>&#8216; + bacc.get(i).getName() &#8216; -&#62; adds the getName() value, which is in<br />
get(i), which is in bacc.</p>
<p>&#8216; + &#8220;, &#8221; &#8216; -&#62; adds a comma and then a space after the above are added.</p></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java 2: Basic Arrays]]></title>
<link>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylists/</link>
<pubDate>Mon, 26 Jan 2009 18:46:11 +0000</pubDate>
<dc:creator>chilloxk</dc:creator>
<guid>http://chilloxk.wordpress.com/2009/01/26/java-3-more-on-arrays-and-basic-arraylists/</guid>
<description><![CDATA[Right now, on a basic level, arrays are fucking fantastic. They are a way of storing data. The data ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Right now, on a basic level, arrays are fucking fantastic.<br />
They are a way of storing data. The data they can store is predefined<br />
by the creator. The size of the array is also predefined. Neither can they<br />
be changed. The fact that the max size cannot be changed is where<br />
arrays fall down, so that&#8217;s why we use ArrayLists. But you need to<br />
understand arrays first.<br />
How you create arrays:<br />
String[] a = new String[5];<br />
This creates an array, which can hold only Strings, it is of size 5.</p>
<p>int[] shit;<br />
shit = new int[10];<br />
The first creates the address block in memory, the second assigns the<br />
size of 10. Mairead is mad for that shit.</p>
<p>Visualise it like so:<br />
{ [] [] [] [] [] }<br />
It starts at 0, so you could consider the element names are<br />
{ a[0], a[1], a[2], a[3], a[4] }</p>
<p>Using for loops is really just about cycling through array&#8217;s elements.<br />
It would be possible, if you wanted to assign all the values of the<br />
int array equal to 0, to do this:<br />
a[0] = 0;<br />
a[1] = 0;<br />
a[2] = 0;<br />
a[3] = 0;<br />
a[4] = 0;<br />
But, as padraic kirwin says in maths, when u get to something of size<br />
1000 it doesn&#8217;t make sense, that&#8217;s where for loops come in.<br />
int[] smash = new int[1000]<br />
// creates an array from  { smash[0], smash[1],&#8230; smash[999] }<br />
for (int i = 0; i &#60;= 999; i++)<br />
{<br />
a[i] = 0;<br />
}<br />
this makes all the elements in the array equal to 0.<br />
why does this work? we&#8217;ll take it section by section.<br />
the for loop is really a better structured while loop. when i write it<br />
i think of it in 3 stages:<br />
stage 1 = &#8220;int i = 0&#8243;, the initialisation stage<br />
stage 2 = &#8220;i &#60;= 999&#8243;, the while stage<br />
stage 3 = &#8220;i++&#8221;, the finalisation stage<br />
here, i provides a counter, but it&#8217;s also a way of accessing the array.</p>
<p>each pass of the loop, a[i] is accessed and made equal to 0.<br />
because at the end of each loop, i++ is &#8216;done&#8217;, which means i is made<br />
what it is currently plus 1. so after the nth pass of the loop, i ==<br />
n.</p>
<p>so you could do different operations to it, such as:<br />
a[i]  = a[i] + 1;<br />
so this would make the value of a[i] equal to its current value, plus one.</p>
<p>a[i] = a[1] * [a2];<br />
this would make the value of a[i], which of course will change each<br />
time, be multiplied by the value of what is in element a[1] and a[2]</p>
<p>you might think ya whatever this is boring, which you are dead right.<br />
The major thing about arrays is that you can store much more than<br />
ints, chars or Strings, you can hold an entire class in each element<br />
of the array,<br />
which is great for storing things like records of information, etc.<br />
when you store a class object in an array, all the methods and fields<br />
can be accessed.<br />
for instance: if we had a method called getName(), in a class Customer.<br />
and we had an array that held customers:<br />
Customer[] list = new Customer[5];<br />
and this array was populated fully, as in it was full of customers:<br />
Customer[0] = cust1;<br />
..etc (cust1 would have to be already created)</p>
<p>we could find the name of the Customer in the Customer[] array, by doing:<br />
Customer[0].getName();</p>
<p>this would mean, we could make a String value equal to this case, for<br />
whatever reason:<br />
String coolest = Customer[0].getName();</p>
<p>if this was in a for loop:<br />
String coolest = Customer[i].getName();</p>
<p>when would you ever use that?</p>
<p>well imagine you wanted to get the name of the person in the array<br />
with the highest balance:<br />
(we need to assume that we have a getter method called getBalance)</p>
<p>public String getHighestBal()<br />
{<br />
int highestBal = 0;<br />
String name = &#8221; &#8220;;<br />
// the reason you need to do that^, is because.. well I don&#8217;t know. i<br />
think it just needs a value, if it is to be updated.<br />
for (int i = 0; i &#60; 5; i++)<br />
{<br />
if ( a[i].getBalance &#62; highestBal )<br />
{<br />
highestBal = a[i].getBalance;<br />
name = a[i].getName;<br />
}<br />
}<br />
return name;<br />
}<br />
what happens:<br />
- goes into a[i], which is initially a[0], and checks the Customer<br />
object in there, checks if the balance is greater than the value we<br />
created &#8216;highestBal&#8217;<br />
if it is, makes the highestBal value equal to it.<br />
then gets the name of the customer in this element of the array and<br />
makes the &#8216;name&#8217; String we created<br />
goes back into the for loop until i is no longer less than 5, then the<br />
return statement is carried out and it exits</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ArrayList vs LinkedList vs Vector]]></title>
<link>http://vidyapsi.wordpress.com/2009/01/22/arraylist-vs-linkedlist-vs-vector/</link>
<pubDate>Thu, 22 Jan 2009 09:37:40 +0000</pubDate>
<dc:creator>vidya</dc:creator>
<guid>http://vidyapsi.wordpress.com/2009/01/22/arraylist-vs-linkedlist-vs-vector/</guid>
<description><![CDATA[ArrayList LinkedList Vector public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; implements]]></description>
<content:encoded><![CDATA[ArrayList LinkedList Vector public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; implements]]></content:encoded>
</item>
<item>
<title><![CDATA[Retrieving unique items from a List in Java]]></title>
<link>http://jaydeepm.wordpress.com/2009/05/07/retrieving-unique-items-from-a-list-in-java/</link>
<pubDate>Thu, 07 May 2009 19:29:20 +0000</pubDate>
<dc:creator>jaydeepm</dc:creator>
<guid>http://jaydeepm.wordpress.com/2009/05/07/retrieving-unique-items-from-a-list-in-java/</guid>
<description><![CDATA[Here is a very simple and efficient way to retrieve unique items from a java.util.List. All you need]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Here is a very simple and efficient way to retrieve unique items from a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html"><code>java.util.List</code></a>.</p>
<p>All you need to do is put all the items in the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html"><code>java.util.List</code></a> into a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html"><code>java.util.Set</code></a> and then create a new <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html">java.util.List</a></code>from the <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html"> Set</a></code>. Since a <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html">Set</a></code> does not allow duplicate entries, the new <code>List</code> created would only have the unique items. </p>
<p>Below is an example:<br />
<code>//the initial List<br />
ArrayList list = new ArrayList();<br />
list.add("ID_1");<br />
list.add("ID_2");<br />
list.add("ID_3);<br />
list.add("ID_2); //duplicate entry - needs to be removed<br />
//convert the List into a Set<br />
Set set = new HashSet(list);<br />
//create a new List from the Set<br />
ArrayList uniqueList = new ArrayList(set);</code></p>
<p>Note that the order of the items in the unique list will not be the same as those in the original.<br />
To maintain the order of the initial items use a <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashSet.html">java.util.LinkedHashSet</a></code> instead of a <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/HashSet.html">java.util.HashSet</a></code>.<br />
To sort the items in the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html"><code>java.util.List</code></a> use a <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TreeSet.html">java.util.TreeSet</a></code> instead. </p>
<p>For further details, have a look <a href="http://www.theeggeadventure.com/wikimedia/index.php/Java_Unique_List">here</a>.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
