How to take input in ArrayList in java when number of values is not a constant? -
i want take input example:
550
234234
874982634
3487239482349
the length of input not fixed , want take input in array list of java.
arraylist<integer> basicpg = new arraylist<integer>();
bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); arraylist<integer> basicpg = new arraylist<integer>(); string input; while((input = br.readline()) != null && input.length() != 0) { basicpg.add(integer.parseint(input)); }
if space seperated, use .split()
bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); string input = br.readline(); string[] tokens = input.split(" "); list<string> wordlist = arrays.aslist(tokens);
Comments
Post a Comment