Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: java array

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java array

    i want to know arrays please be tell us


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java array

    Please read the forum rules, and post your question in the appropriate location. Your thread has been moved.

    I recommend investing some time using resources at your disposal, rather than asking others to spend their valuable time doing this for you. One resource in particular: google java arrays If you have a more specific question that cannot be addressed after you've invested some time researching, then I encourage you to ask.

  3. The Following User Says Thank You to copeg For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  4. #3
    Junior Member
    Join Date
    Jun 2012
    Location
    Birmingham
    Posts
    20
    My Mood
    Depressed
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java array

    hey i believe an array is kind of like a list of a certain data type. for example
    i will make an array of Strings

    String list[] = {"one", "Two", "Three"};

    here i have created an array call list.

    I added three strings to the array "one" " two" and "three".

    The [] means its an array of strings i will show you why.

    typically there is more than one way to declare arrays so i will show you another way.

    String list[] = new String();//this creates the array

    list = new String[3]// this tells the compiler how many string are in your array "3"

    list[0] = "one";// the first of the array starts at 0
    list[1] = "two";//here we declare 3 strings and there index in the array list.
    list[2] = "three";//if your not using strings you do not need the "quotation marks"

    to use either array you would type

    System.out.println(list[0]); // this will print the string at the index 0 aka "one"
    System.out.println(list[1]); // this will print the string at the index 1 aka "two"
    System.out.println(list[2]); // this will print the string at the index 2 aka "three"

    let me know if this helps

  5. The Following User Says Thank You to .Swing For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  6. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: java array

    Quote Originally Posted by .Swing View Post
    String list[] = new String();//this creates the array

    list = new String[3]// this tells the compiler how many string are in your array "3"
    I don't think this will compile. Perhaps you meant

    String[] list = new String[3]; // creates a String array of length 3

    "String list[] = ..." is also possible, but I think it is clearer when you indicate by String[] the type of thing that is being declared - in this case not a String, but an array of String.

  7. #5
    Junior Member
    Join Date
    Jun 2012
    Location
    Birmingham
    Posts
    20
    My Mood
    Depressed
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java array

    no i compiles alright.
    Last edited by .Swing; June 9th, 2012 at 10:12 AM.
    Just be nice.

  8. The Following User Says Thank You to .Swing For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  9. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java array

    Quote Originally Posted by .Swing View Post
    no i compiles alright.
    Please use proper grammar. Saying 'i compiles alright' makes absolutely no sense. This is a programming forum, not a text messaging system. Programmers write code which is extremely syntax dependent - so your sentences should reflect that.

    String list[] = new String();

    No, this will not compile. You cannot assign an array to a String.

  10. The Following User Says Thank You to copeg For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  11. #7
    Junior Member
    Join Date
    Jun 2012
    Location
    Birmingham
    Posts
    20
    My Mood
    Depressed
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java array

    simple spelling mistake does every moderator have to be so arrogant and well. it compiles for me so I believe it does instead of being so critical you could try help a person in a friendly manner instead of being so aggressive.

    I am new to Java and new to this forum. so I am sharing what I have found works for me, I do not mind being corrected in-fact I would not be hear if I was not willing to listen and learn. I would just expect a little more understanding.

    I made a mistake I put "i" instead of "is" not big deal but you say it as if I spoke a different language I am
    pretty sure although a mistake on my part, it would take you no more than two seconds to realise it is supposed to be is....

    thank you
    Last edited by .Swing; June 9th, 2012 at 12:22 PM.
    Just be nice.

  12. The Following User Says Thank You to .Swing For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  13. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java array

    Quote Originally Posted by .Swing View Post
    simple spelling mistake does every moderator have to be so arrogant and well. it compiles for me so I believe it does instead of being so critical you could try help a person in a friendly manner instead of being so aggressive.
    Its a moderators duty (moderators who do this unpaid and in their spare time) to prevent confusion. Having been doing this for years, I have seen my fair share of confusion lead to people wasting time, questions not getting answered, people getting sidetracked, and worst of all learning incorrectly. Asking someone to write with proper grammar is not arrogance, nor is it critical - it's to prevent confusion. And writing it bluntly is not arrogance or criticism, its a side affect of the impersonal nature of forums such as this. I would like to hope members contributing here do not want their questions or responses to lead to confusion, and would take advice given to them in a respectful and understanding way.
    Last edited by copeg; June 9th, 2012 at 12:47 PM.

  14. The Following User Says Thank You to copeg For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  15. #9
    Junior Member
    Join Date
    Jun 2012
    Location
    Birmingham
    Posts
    20
    My Mood
    Depressed
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java array

    I know the duty of a moderator I am just saying there is better ways of spending your time than correcting none code related spelling issues.
    As you could tell I was not using text slang It was merely a single missing letter. pointing it out the way you did suggests arrogance.
    I do appreciate you time and help, I was just stating your correction of a simple missing letter I the manner you did so was not needed.
    from my single day on this forum I have found that moderators such as you seem to talk down to people asking questions, for example.

    a new guy joins the forum and asks a question
    i want to know arrays please be tell us
    he is met with the response
    Please read the forum rules, and post your question in the appropriate location. Your thread has been moved.

    I recommend investing some time using resources at your disposal, rather than asking others to spend their valuable time doing this for you. One resource in particular: google java arrays If you have a more specific question that cannot be addressed after you've invested some time researching, then I encourage you to ask.
    can you not see how this type of response to a simple question could make this person feel as if this forum is not going to help an simply just
    pawn him off to another site or otherwise make him/her go elsewhere.
    Just be nice.

  16. The Following User Says Thank You to .Swing For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  17. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java array

    Quote Originally Posted by .Swing View Post
    can you not see how this type of response to a simple question could make this person feel as if this forum is not going to help an simply just
    pawn him off to another site or otherwise make him/her go elsewhere.
    I am not going to itemize my reasons for the format of my response. Suffice it to say my time is valuable to me (and valuable to all the other people here (and elsewhere) asking questions) - so why should I spend my time reproducing what has been said (and said much better than I could say) elsewhere, and can be easily found with a little effort?

    If you wish to discuss this further, then please take the discussion to its own topic, PM or conversation rather taking this thread completely off topic. I would rather not have to lock this thread because of it

  18. The Following User Says Thank You to copeg For This Useful Post:

    Kaluarachchi (June 12th, 2012)

  19. #11
    Junior Member
    Join Date
    Jun 2012
    Location
    Birmingham
    Posts
    20
    My Mood
    Depressed
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java array

    thank you for your time I just hope you take a little regard for others feelings when telling people to do it them self, an not to ask for a little help on a forum.
    Just be nice.

Similar Threads

  1. Replies: 4
    Last Post: November 14th, 2011, 10:00 PM
  2. Java Uneven 2D Array
    By ba.accounts in forum Collections and Generics
    Replies: 5
    Last Post: August 10th, 2011, 07:38 AM
  3. returning 2d array in java
    By dr.code.skm in forum Member Introductions
    Replies: 2
    Last Post: July 20th, 2011, 10:14 AM
  4. Java Array
    By lary in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 12th, 2011, 09:29 AM