The Artima Developer Community
Sponsored Link

Java Answers Forum
array initialize problem

3 replies on 1 page. Most recent reply: Dec 8, 2003 2:51 AM by Vinayan Menon

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Joy

Posts: 15
Nickname: papai
Registered: Nov, 2003

array initialize problem Posted: Nov 30, 2003 11:17 PM
Reply to this message Reply
Advertisement
After int arr[]=new int[4] ; how can i initialize array element
without explicitely arr[0],arr[1],arr[2]......arr={2,5,7,8} not working?


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: array initialize problem Posted: Dec 1, 2003 12:15 AM
Reply to this message Reply
Seems like you have taken a Java book and rolling on :-)

May be this would help....

int arr[] = {2,5,7,8}

Joy

Posts: 15
Nickname: papai
Registered: Nov, 2003

Re: array initialize problem Posted: Dec 8, 2003 12:53 AM
Reply to this message Reply
hello i want to have this after initialize array using new.
how to do it?reply if u know.

Vinayan Menon

Posts: 1
Nickname: vmm
Registered: Nov, 2003

Re: array initialize problem Posted: Dec 8, 2003 2:51 AM
Reply to this message Reply
Try this, it works..

public class Test {

public static void main(String args[]) {

int arr[] = new int[4];

for (int i = 0 ; i < arr.length ; i++)
arr = i;
}
}

Cant understand why it doesnt work for you. You seem to have got something wrong. Send over the source if you still cant figure it out...

Regards

Flat View: This topic has 3 replies on 1 page
Topic: 2 dimension array of objects.how do i initialize values; Previous Topic   Next Topic Topic: Version Numbering - Best Practice?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use