Results 1 to 2 of 2
  1. #1
    moni sharma is offline Member
    Join Date
    Jan 2011
    Rep Power

    Post based on array limit

    hello all,
    plz guide me how i modify the programm so that the array become dynamic means no need to give its in this program limit is 5.
    its taking input more t 5 but output is applycable for 5 only...
    plz modify,.......


    import java.util.*;
    class ArrayExample2
    public static void main(String[] args)
    Scanner input=new Scanner(;
    int array[]=new int[5];
    System.out.println("Enter Array Elements: ");
    for(int i=0;i<array.length;i++){
    System.out.println("Your Array Elements are: ");
    for(int i=0;i<array.length;i++){

  2. #2
    user0 is offline Senior Member
    Join Date
    Dec 2010
    Rep Power


    Hi Moni - an array is of fixed length determined when you create it. If you want to have a more flexible structure that will increase its size automatically as you add more inputs, you might want to consider ArrayList. They work just like arrays, except you cannot use them with the primitive types such as int. Hence, there are wrapper classes that can be used to store primitives in ArrayLists. The constructor is:
    Java Code:
    ArrayList<Integer> array = new ArrayList<Integer>();
    To access an element at index 2, for example, you will do:

    Java Code:
    For a complete method listing, please see the Java Api : ArrayList (Java Platform SE 6)


Similar Threads

  1. i need an example of JSR179 ((Location based Ser)implementation for CDC based device
    By talk_to_vivekmishra in forum CDC and Personal Profile
    Replies: 3
    Last Post: 12-30-2010, 11:07 AM
  2. decimal limit help
    By Newtothis in forum New To Java
    Replies: 3
    Last Post: 11-16-2010, 07:37 PM
  3. Concatinating contents of a string array based on condition
    By gangsterooseven in forum Advanced Java
    Replies: 2
    Last Post: 10-07-2009, 08:35 AM
  4. array-based implementation question
    By intelli in forum New To Java
    Replies: 1
    Last Post: 04-18-2009, 06:18 PM
  5. Can you Limit JSpinners??
    By ashton in forum New To Java
    Replies: 1
    Last Post: 02-09-2009, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts