Arrays
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Arrays

  1. #1
    Join Date
    Oct 2017
    Posts
    1

    Arrays

    I am looking for the better way to do arrays, This is my way but I am not sure if it is suitable.

    Code:
    package arraylist;
    
    import java.util.ArrayList;
    
    /**
     *
     * @author chris
     */
    public class Arraylist {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
             
     
    
    	  /*This is how elements should be added to the array list*/
    	ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
    		weeklyTemperatures.add(78);
    		weeklyTemperatures.add(67);
    		weeklyTemperatures.add(89);
    		weeklyTemperatures.add(94);
    		weeklyTemperatures.add(2, 111);
                    System.out.println(weeklyTemperatures.get(0));
                    
        }
        
    }

  2. #2
    Join Date
    Aug 2017
    Posts
    36

    Re: Arrays

    There is a better way to access elements of an array by using looping construct .

    Code:
    class ArrayExample {
       public static void main(String[] args) {
    
          int[] age = new int[5];
    
          for (int i = 0; i < 5; ++i) {
             System.out.println(age[i]);
          }
       }
    }
    Last edited by 2kaud; November 24th, 2017 at 04:06 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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)