Results 1 to 5 of 5

Thread: ArrayList Collection problem in java

  1. #1
    Join Date
    Mar 2010
    Posts
    360

    ArrayList Collection problem in java

    Hello,
    I try to translate a program with tables list string using the ArrayList collection and from the beginning I'm falling in a stalemate that does not allow me to continue the translation:

    Code:
    	ArrayList list = new ArrayList (); 
    	lst.add (Integer.parseInt (str [0])); 
    	lst.add (Integer.parseInt (str [1])); 
    	lst.add (Integer.parseInt (str [2] )); 
    	lst.add (Integer.parseInt (str [3])); 
    	char class = '' if (lst.get (0) <127 & & lst.get (0)> 0) (System.out.println ("Your ip address is Class A") class = 'A';)
    Level error condition, if you could help me with this. Thank you.

  2. #2
    Join Date
    Dec 2009
    Posts
    213

    Re: ArrayList Collection problem in java

    Its been a while since I have not done java, once I'm not too sure of myself, but if I understand well your problem, you would like to replace.

    int cat = Integer.parseInt (str [0]); Intl H1 = Integer.parseInt (str [1]), int H2 = Integer.parseInt (str [2]), int H3 = Integer.parseInt (str [3] )

    by using an array lst?
    just as in this example:

    ArrayList lst = new ArrayList (); ls.add (ip.split ("\ \.")) Int cat = Integer.parseInt ((String) ls.get (0)) if (class <127 & & Class> 0 ) (System.out.println ("Your ip address is Class A") class = 'A'

    and the problem in this example is that java does not cast to an element of an ArrayList to a string.
    tries may be declaring your array as its lst:

    <String> ArrayList lst = new ArrayList ();

    if its running there Aurra probably less hassle to go from one element of a string ArrayListe then an int as you attempt to do in this line:
    int cat = Integer.parseInt ((String) ls.get (0));

    More help is provided here Collections in Java

  3. #3
    Join Date
    Mar 2010
    Posts
    360

    Re: ArrayList Collection problem in java

    I tried something else:
    Code:
    ArrayList list = new ArrayList (); liste.add (ip.split ("\ \.")) Int category = Integer.parseInt ((String) liste.get (0)) if (class <127 & & Class> 0 ) (System.out.println ("Your ip address is Class A") class = 'A';)
    Even this is not working for me. More help is appreciated. Thank you.

  4. #4
    Join Date
    May 2008
    Posts
    222

    Re: ArrayList Collection problem in java

    I think this is not possible to use the collections in this kind of program, given what will accept any kind and I do not know how to make distinctions between types in the case of chained lists.

  5. #5
    Join Date
    Dec 2009
    Posts
    296

    Re: ArrayList Collection problem in java

    It obviously just the problem that Java can not be cast to the contents of your list is like
    "java.lang.String" in a type "java.lang.String".
    You should try can be put "lst.get (0)" in a String variable means by causing something like:
    String = temp (lst.get (0)). ToString ();
    and after you do:
    int category = Integer.parseInt (temp);

Similar Threads

  1. Multidimensional ArrayList in java
    By Aaliya Seth in forum Software Development
    Replies: 6
    Last Post: 16-02-2011, 01:03 AM
  2. Multidimensional ArrayList in Java
    By Navp in forum Software Development
    Replies: 1
    Last Post: 05-02-2011, 12:43 AM
  3. Java - help with Garbage Collection
    By Messenger in forum Software Development
    Replies: 4
    Last Post: 23-07-2010, 10:18 AM
  4. How to sort items of an ArrayList in java?
    By hounds in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 07:46 PM
  5. Problem in modifying value of ArrayList Object of JAVA
    By Praetor in forum Software Development
    Replies: 3
    Last Post: 16-11-2009, 09:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,251,778.25549 seconds with 17 queries