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)); } 

1st case 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);  

enter image description here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -