-
October 27th, 2017, 12:41 PM
#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));
}
}
-
November 24th, 2017, 12:53 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|