This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

array problem  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i development all array of 20students?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 217
  • Mark post as helpful
  • send pies
  • 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: 217
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have learned about for loops?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 217
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • 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.
     
    Liutauras Vilda
    Marshal
    Posts: 4650
    318
    BSD
    • Mark post as helpful
    • send pies
    • 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: 4073
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • 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.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!