Java - leer listas desde el std input

 
Vista:

leer listas desde el std input

Publicado por LUIS ARTURO (5 intervenciones) el 12/01/2006 23:35:07
hola estoy desarrollando un programa que lee, inserta, borra imprime etc.. strings(hora y fecha) dentro de un ciclo en el std in. ya casi lo termino sin embargo tengo algunas dudas por ejemplo como le puedo decir dentro del ciclo que me ponga un elemento en la posicion que yo quiera ?(add) y lo mismo para borrar y obtener el elemento en el indice especificado?
como hago uso del metodo set? cualquier ayuda se los agradecere muchas gracias aqui esta el fuente:


/*_____________________________________________________________________________
*
* Clase:
*
* Archivo: StdInput.java
*
* Fecha: 03 Enero del 2006 -> creacion
*
* Autor: Luis Arturo
*
* Proposito: aplicar los metodos del java collection framework
*
*___________________________________________________________________________*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
import java.text.*;
public class StdInput
{
public static void main ( String argv [ ] )
{

/*_____________________________________________________________________________
*
* MAIN
*___________________________________________________________________________*/

//---creating objects---
BufferedReader in = null;


String line = null,
s = null;
// insert = null;
LinkedList list = null;

Calendar calendar = null;

Date date = null;

SimpleDateFormat localFormat = null;



Integer i = null;
int x = 0,
y = 0;
list = new LinkedList ( );



//---handle the error with exception---
//---instances of the class---


in = new BufferedReader (new InputStreamReader ( System.in ));

int insert = 0;

try{

//--- a cycle remains until both boolean be true ---
while ((insert = Integer.parseInt( in.readLine( ))) != 12 )
{
calendar = new GregorianCalendar ( );
date = calendar.getTime ( );
localFormat = new SimpleDateFormat ( "dd/MMM/yyy" );
s = localFormat.format (new Date( ));
if (insert == 0 )
{

System.out.println ("number of items added at the list: "+ list.size( ));
}

if (insert == 1 )
{

list.addFirst ( s +" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND) );

System.out.println( list.indexOf (s +
" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND)));




}
if (insert == 2)
{
int index
list.add (y, s+" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND) ) ;
}
if (insert == 3 )
{
list.addLast ( s+" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND) ) ;
}
if (insert == 4 )
{
System.out.println ( list.getFirst ( ));
}
if (insert == 5)
{
System.out.println ( list.getLast ( ));
}
if (insert == 6 )
{
Object remove = list.removeFirst ( );
}
if (insert == 7 )
{
Object remove = list.removeLast ( );
}


if (insert == 8 )
{
ListIterator ite = list.listIterator( );
while (ite.hasNext ( ))
{
line = ( String ) ite.next ( );

System.out.println (line);

//System.out.println (line+ list.indexOf (s +
//" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
// calendar.get(calendar.MINUTE)+":"+
// calendar.get(calendar.SECOND)));
}
}
}


}

catch(IOException e)
{
System.err.println ("found a exception"+ e.toString( ));
}

} /*________________________END OF MAIN METHOD______________________________*/
}/*_________________________END OF StdInput CLASS____________________________*/
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder