Re: crear vector de vectores

Sebastian Gurin <sgurin-nLx/x0uvtyR/[email protected]>
Newsgroups gmane.comp.java.javaspain
Organization softpoint
Message-ID <[email protected]>
lo que tu quieres son cosas que se contengan a si mismas. Te recomiendo que diseñes una clase Composite (http://es.wikipedia.org/wiki/Composite_(patr%C3%B3n_de_dise%C3%B1o))

suerte

On Wed, 06 May 2009 02:32:48 -0000
"commodin" <commodin-/[email protected]> wrote:

> Hola, necesito ayuda con un juego que estoy creando. El problema es el siguiente:
> 
> Durante el desarrollo del juego el usuario podra crear cajas. Dentro de una caja podra crear algunos objetos u otras cajas. Dentro de esas cajas podrá hacer lo mismo. Así indefinidamente.
> 
> Intente resolver el problema haciendo un vector de vectores de la siguiente forma:
> 
> import java.util.*;
> public class NewClass {
>   public static void main(String[] args){
>     ArrayList<String> caja1 = new ArrayList<String>();
>     ArrayList<String> caja2 = new ArrayList<String>();
>     ArrayList<ArrayList<String>> caja3 = new ArrayList<ArrayList<String>>();
>     caja1.add("1");
> 		caja1.add("2");
> 		caja2.add("rafa");
>     caja2.add("el");
>     caja3.add(caja2);
>     caja3.add(caja1);
>     System.out.println(caja3.get(0).get(0));
>     System.out.println(caja3.get(0).get(1));
>     System.out.println(caja3.get(1).get(0));
>     System.out.println(caja3.get(1).get(1));
>   }
> }
> 
> El problema consiste en que de esa forma no se pueden crear vectores que contengan vectores, que a su ves contengan vectores, etc...
> 
> Les agradezco me colaboren con alguna solución que ojalá permita acceder a cualquier elemento de cualquier vector facilmente.
> 
> 


-- 
Sebastian Gurin <sgurin-nLx/x0uvtyR/[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.