3 Replies Latest reply: May 20, 2008 5:40 AM by masijade RSS

    How to put int values one by one in an int array

    807601
      Hi,

      I am trying to put the int value into int array(int []). But while compiling I am getting incomptable type.
      List list2 = new ArrayList();
                list1.add("0001 abc");
                list1.add("0002 aa");
                String segData = "HotelItinerarySeg IsPastDate=false RoomQuantity=1 SegNo=0002";
                int [] ab = null;
           for(int i=0;i<list1.size();i++){
                     if(segData.indexOf("SegNo")!=-1){
                          System.out.println("peint:"+segData.indexOf("SegNo"));
                          int k = segData.indexOf("SegNo");
                          String sub = segData.substring(k+6,k+10);
                          ab = Integer.parseInt((String)sub); //Here I am trying to pu the element one by one in int [].
                          //System.out.println(ab);
                     }
           }
      Please help me on this issue.
        • 1. Re: How to put int values one by one in an int array
          807601
          Hi.

          Your ab variable is an array (you should also alocate some memory for it using new operator)

          When you write ab = Integer.parse... you say - make my array reference point to an int. An array reference can point to array but not to int.

          Regards,
          • 2. Re: How to put int values one by one in an int array
            807601
            G.W. wrote:
            Hi.

            Your ab variable is an array (you should also alocate some memory for it using new operator)

            When you write ab = Integer.parse... you say - make my array reference point to an int. An array reference can point to array but not to int.

            Regards,
            What I have to change in the code. Currently I am getting the below error message.

            Testing.java:22: incompatible types
            found : int
            required: int[]
            ab = Integer.parseInt((String)sub);
            ^
            • 3. Re: How to put int values one by one in an int array
              masijade
              ggopi wrote:
              G.W. wrote:
              Hi.

              Your ab variable is an array (you should also alocate some memory for it using new operator)

              When you write ab = Integer.parse... you say - make my array reference point to an int. An array reference can point to array but not to int.

              Regards,
              What I have to change in the code. Currently I am getting the below error message.

              Testing.java:22: incompatible types
              found : int
              required: int[]
              ab = Integer.parseInt((String)sub);
              ^
              You've been coming to this forum for nearly two years now, and you still don't know how to index into an array? I always knew you were a hopeless case, but you've just proven it, beyond a doubt.