java - Print all the values of the List except the last one. -


i have code:

list<integer> list1 = new arraylist<integer>();     list1.add(100);     list1.add(200);     list1.add(300);     list1.add(400);     list1.add(500);     list1.add(600);  integer lastelement = list1.get(list1.size()-1);  system.out.println("values of list:" + list1-lastelement); !!! 

the values of list should be: 100, 200, 300, 400, 500. , list1-lastelement gives me error! there other way it?

what trying subtract value 600 (the last value of arraylist) length of arraylist. makes no sense. instead try following (if trying print last element):

for (int = 0; < list1.size() - 1; i++) {      system.out.println(list1.get(i)); } 

what print last element. hence

list1.size() - 1 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -