Results 1 to 2 of 2
  1. #1
    JeroenV is offline Member
    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Default Properties file scattering lists

    Hello,

    I've been trying to save lists into a properties file so I could have show the lists as an array. However, when I try to for loop using .setProperty(key,value) it doesn't keep its normal order.

    Here's the code example:

    Java Code:
        	Properties test = new Properties();
        	
            for(int j=0;j<=36;j++){
                test.setProperty(j+"",j+"");
            	for(int i=0;i<=36;i++){
            }}
    While I would expect this would save as:
    Java Code:
    0=0
    1=1
    ...
    This is what I actually get:
    Java Code:
    29=29
    28=28
    27=27
    26=26
    25=25
    24=24
    23=23
    22=22
    21=21
    20=20
    9=9
    8=8
    19=19
    7=7
    18=18
    6=6
    17=17
    5=5
    16=16
    4=4
    15=15
    3=3
    14=14
    2=2
    13=13
    1=1
    12=12
    0=0
    11=11
    10=10
    36=36
    35=35
    34=34
    33=33
    32=32
    31=31
    30=30
    For some reason all the numbers are scattered..

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Properties file scattering lists

    The properties file doesn't guarantee the order. It's like a set or bag. Set (abstract data type) - Wikipedia, the free encyclopedia

    If the only reason you're storing the list in the properties file is to convert it to an array, that's an awfully circuitous way to do it. Just use List (Java Platform SE 6)[]%29.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Reading properties file
    By nn12 in forum New To Java
    Replies: 3
    Last Post: 09-13-2014, 01:48 PM
  2. ResourceBundleViewResolver properties file
    By frenk_castle in forum Web Frameworks
    Replies: 1
    Last Post: 04-07-2011, 08:39 PM
  3. Accessing Properties File
    By java_men in forum Java Servlet
    Replies: 0
    Last Post: 05-11-2010, 12:34 PM
  4. Unable to access velocity.properties file from jar file
    By mjwoodford in forum New To Java
    Replies: 0
    Last Post: 10-09-2009, 02:46 PM
  5. Replies: 10
    Last Post: 10-03-2009, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •