#Array List Help

1 messages · Page 1 of 1 (latest)

stuck sphinx
#

Im lost on array lists I am confused on implementing them properly

chrome tuskBOT
#

Hey, @stuck sphinx!
Please remember to /close this post once your question has been answered!

stuck sphinx
#
  1. Declare an ArrayList of Double and call constructor to create the ArrayList
  2. Prompts the user to enter 5 numbers, stores them in the ArrayList
  3. Display the contents of the list by invoking the toString() method. System.out.println(list);
  4. Invoke the built in sort method. java.util.Collections.sort.
  5. Display the list. (It should be sorted in increasing order. _
  6. Use java.util.Collections.shuffle(list); to rearrange the list
  7. Print out the shuffled list -- write a loop for this, rather than using the toString() method. Have the loop condition check when to stop by using size() method, rather than hard coding a number.
  8. Display the minimum and largest value in the list by using the min and max methods.
#

this is what I need to do

#
import java.util.List;
import java.util.Scanner;

public class ArrayList {
    //NEED TO FIGURE OUT PROPER ARRAY LIST and how to sort properly

    public static void main(String[] args) {
        List<Double> list = new java.util.ArrayList<>();
        Scanner input = new Scanner(System.in);

        System.out.println("Please Enter 5 Numbers");
        for (int i=0; i<5; i++){
            System.out.println("Please enter "+i+ " number");
            list.add(input.nextDouble());
        }

        System.out.println(list.toString());
    }
}
#

this is my code, unsure how to properly set up an arraylist

low mantle
#

We're not just gonna do your homework for you; what specifically are you having trouble with? It looks like your code will work

stuck sphinx
#

I'm showing like what I am trying to accomplish and I dont know how to really declare an array list of double

#

thats where I am stuck

low mantle
#

you did already

#

you're not stuck

#

you literally did it correctly

stuck sphinx
#

thats an array list?

#

am I sorting wrong then?

#

oh

#

uh

#

I could be mentally handicap

#

I copy and pasted my arrayList is there any better way to do it

low mantle
#

I think you should just read the javadoc for List or ArrayList, it explains everything