#ArrayList

10 messages · Page 1 of 1 (latest)

warm heart
#

Why my output be like this? Whenever I use <space> it being assigned to next variable?

sullen tideBOT
#

This post has been reserved for your question.

Hey @warm heart! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

warm heart
#

import java.util.*;

public class ArrList {
static Scanner sc = new Scanner(System.in);
    public static void display() {
        System.out.print("Enter size of array : ");
        int size = sc.nextInt();
        
        ArrayList<String> appliances = new ArrayList<String>(size);
        for(int x = 0; x < size; x++) {
            System.out.print("Add some appliance/s : ");
            appliances.add(sc.next());
        }
        System.out.println();
        System.out.println("Display Current Array\n");
        for(int y = 0; y<size; y++) {
            System.out.println(y + ". " + appliances.get(y));
        }
        System.out.println("Current Array Size : " + appliances.size());
        System.out.print("\nEnter the scdex of appliances you want to remove : ");
        int id = sc.nextInt();
        appliances.remove(id);
        System.out.println("\nDisplay Updated Array");
        for(int z = 0; z < appliances.size(); z++) {
            System.out.println(z + ". " + appliances.get(z));
        }
        System.out.println("Updated Array Size : " + appliances.size());
    }
    
    public static void main(String[] args) {
        display();
    }
}
#

this is my source code

exotic imp
#

yeah next() reads until the next whitespace, not the entire input/line

#

use nextLine, and also

sullen tideBOT
#

If Scanner#nextLine reads an empty line after calling a different Scanner#next method, take a look at this StackOverflow post.

warm heart
sullen tideBOT
# warm heart Thanks for the info. man

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.