• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array problem

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i development all array of 20students?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you expand your question a little? Do you have a class called Students? If so, you can create an array of 20 Students like this:
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Could you expand your question a little? Do you have a class called Students? If so, you can create an array of 20 Students like this:

yes I have this and I want to system.out.println this array
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Could you expand your question a little? Do you have a class called Students? If so, you can create an array of 20 Students like this:

yes I have this and I want to system.out.println this array . I want everything has inside the array to system out .I can't find the code
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have learned about for loops?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes Arrays.toString() will be enough, but if you want to do something with the objects in the array, then some kind of loop, like a for loop, is necessary.
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first i dont know what does this :

Knute Snortum wrote:Sometimes Arrays.toString() will be enough, but if you want to do something with the objects in the array, then some kind of loop, like a for loop, is necessary.

second question i want to see the content of an array (only a array) example :

Output:
Java Example to print int array in Java: [I@1820dda
Java Example to print string array in Java: [Ljava.lang.String;@15b7986
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, Java Example to print String array values in Java 1.4 :[abc, bcd, def, efg]
Java Example to int array values in Java 1.4 :[[I@1820dda]
Java Example to print values of array in Java: [1, 2, 3, 4, 5]
Java Example to print values of array in Java: [abc, bcd, def, efg]
Java Example to print two dimensional array in Java: [[1, 2, 3], [10, 20, 30], [100, 200, 300]]


Read more: http://javarevisited.blogspot.com/2012/12/3-example-to-print-array-values-in-java.html#ixzz43cirhe4E i want this code to search only in the same array and 1 dimensions string and int . How can i do that?also on my array i use userinput .How can i express it on my array that i use userinput ?i mean on the array it is like this private static int[] intArray = new int[]{ 2,3,4, 5,7}; i want to use userinput to complete the array and after to development to my window
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My, where did you find that tutorial? I can see two errors already:-
  • 1: It uses pre-Java5 code; you should forget everything which happened before Java5.
  • 2: It says it prints type of the elements. That is incorrect. It prints the name of the class which the array is derived from. That is subtly different from the element type. Look at the “type” of your int[].
  • The tutorial says that the “type” and hashcode are printed, but it doesn't tell you that is because arrays do not override the toString() method.

    You had your code tags in the wrong place, but don't worry; I have corrected them.
     
    Marshal
    Posts: 8857
    637
    Mac OS X VI Editor BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There are more issues with that tutorial.

  • Poor variables naming, couple of them: twoDimensionArray, sArray, iArray (would understand if would be Apple thing or something).
  • Code indentation also could be improved in every single example provided. No spaces around operators "=", "<". Inconsistent formatting too.
  • Code does not compile in at least one example because of missing opening "(".
  • They keep repeating about printing two-dimensional arrays in Java. In Java there are arrays of one dimension only. Where each element could hold another array. That is called array of arrays.

  • We had multiple questions last week about array of arrays, you could look up for questions in Beginning Java. Usually these start with 2D

    OP's linked tutorial wrote:...Print values of Integer array in Java

    Be careful, Integer in Java is a class, which wraps a value of primitive data type int into an object. You don't do that here. Java arrays can hold a primitive data type.
     
    Knute Snortum
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    This is a special form of a for loop that I think people call a for each loop or extended-for loop. It iterates through the list, putting each element into value. You can think of it this way:

    It works on arrays too.
     
    expectation is the root of all heartache - shakespeare. tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic