Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
i have an error while trying to insert 09 in my ArrayList's add method how to resolve it
when i google for it its give me solution like its a octal no and i need to chage this to decimal no
how do i do this please any one help me ...
Java
import java.util.*;
class MyArrayList{
   public static void main(String args[]){
        ArrayList al=new ArrayList();
        al.add(new Integer(09));
        System.out.println(al);
   }
}


<br />
output:MyArrayList.java:5:error integer too large:09<br />
Posted

1 solution

As have been already told to you, integer literals starting with zero are considered having octal base (and, you know, allowed digit of octal base are {0,1,2,3,4,5,6,7}). If you need to add the decimal 9 to the ArrayList then you have to remove the heading '0', that is change from
Quote:
al.add(new Integer(09));
to
Java
al.add(new Integer(9));
 
Share this answer
 
v2
Comments
Patrice T 10-Oct-15 13:05pm    
+5{0,2,3,4,5,6,7} is missing 1 :)
CPallini 10-Oct-15 15:39pm    
Thank you very much. Fixed now.
jagdish vaghela 11-Oct-15 9:14am    
This method is also i know but there is any solutions for do such this type of operation
CPallini 11-Oct-15 10:04am    
Solution to what? If 09 is meant to be an octal literal then it is wrong. If it is meant to be a decimal literal then write it properly (that is 9). If ti comes from a string the use the parseInt method to convert directly the string to integer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900