• print arraylist of arrays
    13 replies, posted
Hi all, I have a question and did not find anything in the internet, so i ask to you how can i do for print a arralist of array in java??
[QUOTE=felesmiki;44623302]Hi all, I have a question and did not find anything in the internet, so i ask to you how can i do for print a arralist of array in java??[/QUOTE] Nested loops.
[code] ArrayList<String> stringList = new ArrayList<String>(); stringList.add("element one"); stringList.add("element two"); for (String string : stringList) System.out.println(string); [/code] [editline]23rd April 2014[/editline] Use Google next time. This stuff is very basic.
[QUOTE=Contron;44623740][code] ArrayList<String> stringList = new ArrayList<String>(); stringList.add("element one"); stringList.add("element two"); for (String string : stringList) System.out.println(string); [/code] [editline]23rd April 2014[/editline] Use Google next time. This stuff is very basic.[/QUOTE] [code]public class supermercado { public static void main (String arcs[]){ java.util.Scanner dato = new java.util.Scanner(System.in); ArrayList listado = new ArrayList(); String datosprod[] = new String [3]; listado.add(datosprod); boolean finproducto = true; boolean productoinfo = true; String productoentero = ""; int y = 0; int x = 0; while(finproducto){ String datos = dato.nextLine(); if(datos.length()>=14){ char valor1 = datos.charAt(x); String valor2 = Character.toString(valor1); if(!(valor2.equals(" "))){ productoentero = productoentero + valor2; if(x==datos.length()-1){ productoinfo=false; } }else{ productoinfo=false; } if(!(productoinfo)){ datosprod[y]=productoentero; productoentero = ""; productoinfo=true; y++; if(y==3){ listado.add(datosprod); y=0; } } x++; if(x==datos.length()){ x=0; } }else{ listado.add(datos); finproducto = false; } } } }[/code] i used google for this, but did not find anything that works on me program ( And i see that this probably will be easy posting this before)
You really should use camelCase to make your identifiers more readable. I can't read Spanish well, but if you marked word boundaries it would at least be easier to guess what it's supposed to do.
[QUOTE=felesmiki;44623769][code]public class supermercado { public static void main (String arcs[]){ java.util.Scanner dato = new java.util.Scanner(System.in); ArrayList listado = new ArrayList(); String datosprod[] = new String [3]; listado.add(datosprod); boolean finproducto = true; boolean productoinfo = true; String productoentero = ""; int y = 0; int x = 0; while(finproducto){ String datos = dato.nextLine(); if(datos.length()>=14){ char valor1 = datos.charAt(x); String valor2 = Character.toString(valor1); if(!(valor2.equals(" "))){ productoentero = productoentero + valor2; if(x==datos.length()-1){ productoinfo=false; } }else{ productoinfo=false; } if(!(productoinfo)){ datosprod[y]=productoentero; productoentero = ""; productoinfo=true; y++; if(y==3){ listado.add(datosprod); y=0; } } x++; if(x==datos.length()){ x=0; } }else{ listado.add(datos); finproducto = false; } } } }[/code] i used google for this, but did not find anything that works on me program ( And i see that this probably will be easy posting this before)[/QUOTE] What on earth do beginner programmers have against spaces and line breaks?
[CODE]ArrayList<int[]> myArray = new ArrayList<int[]>(); //Fill your array here for(int[] arrayToPrint: myArray){ for(int a: arrayToPrint){ System.out.print(a + "\t"); } System.out.print("\n"); }[/CODE]
[QUOTE=Speedfalcon;44625431][CODE]ArrayList<int[]> myArray = new ArrayList<int[]>(); //Fill your array here for(int[] arrayToPrint: myArray){ for(int a: arrayToPrint){ System.out.print(a + "\t"); } System.out.print("\n"); }[/CODE][/QUOTE] You know...there is this method...called println() ? :v: Also looping through Arrays with "for(Type var : int[])" was just implemented a while ago, so make sure you have the latest Java Version :D
[QUOTE=johnnyaka;44625733]You know...there is this method...called println() ? :v: Also looping through Arrays with "for(Type var : int[])" was just implemented a while ago, so make sure you have the latest Java Version :D[/QUOTE] Foreach loops using the semicolon were introduced with Java 5 in 2004. I don't think he needs to worry.
[QUOTE=Contron;44625839]Foreach loops using the semicolon were introduced with Java 5 in 2004. I don't think he needs to worry.[/QUOTE] Well, you don't know how many Sysadmins still use old Java-Versions (( My school e.g still uses Java 4 and don't ask me why ))
[QUOTE=Perl;44625007]What on earth do beginner programmers have against spaces and line breaks?[/QUOTE] I know what you mean, I help two of my friends at Uni with their programming stuff and they both have two very different styles. One of them puts in a ton of line breaks and the other puts in a few but in weird places so the code is just in blocks that make no sense. I die a little inside whenever I am watching over them.
Seeing any of these things makes me cry and wonder if the programmer has a broken spacebar: [code]){ x<y x=y for(x;y;z) }else{[/code]
[QUOTE=sambooo;44644748]Seeing any of these things makes me cry and wonder if the programmer has a broken spacebar: [code]){ x<y x=y for(x;y;z) }else{[/code][/QUOTE] To be fair to OP, he isn't claiming to be some genius or expert programmer. Habits like proper formatting comes with time and experience.
[QUOTE=Hng;44652641]To be fair to OP, he isn't claiming to be some genius or expert programmer. Habits like proper formatting comes with time and experience.[/QUOTE] or literally any IDE
Sorry, you need to Log In to post a reply to this thread.