Results 1 to 7 of 7
Thread: Efficiency of code...
 09262010, 07:45 AM #1Member
 Join Date
 Jul 2010
 Posts
 11
 Rep Power
 0
Efficiency of code...
Hello, I have a simple question.
I am just wondering out of curiosity, which of the following two methods for loading a series of numbers from a text file, converting them to an integer and loading them into an array is the most efficient?
The input file looks like the following:
11111111111111111111
10000000000000000001
10111111001000000001
10100000001111111111
10100011111000000001
10100000001000100001
10100000031000100001
10111111111000100001
10000000000000100021
11111111111111111111
Java Code:for (int i = 0; i < 10; i++) { temp = input.nextLine(); for (int j = 0; j < 20; j++) { // position[i][j] = Integer.parseInt(temp.charAt(j)+""); // <Method one position[i][j] = Character.getNumericValue(temp.charAt(j)); // <Method two } }
Or is there some other, more efficient method of loading entire text files whose contents contain only numbers and the number of rows and columns are known (as in above, 10 rows, 20 columns) into a 2D array of integers?
Thanks in advance =).
 09262010, 07:54 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
 09262010, 08:15 AM #3Member
 Join Date
 Jul 2010
 Posts
 11
 Rep Power
 0
Thank you! :)
 09262010, 08:39 AM #4Member
 Join Date
 Sep 2010
 Posts
 33
 Rep Power
 0
If you know that there are ever Latin digits 09 then the efficient solution is:
position[i][j] = temp.charAt(j)  '0';
But if you expect the Arabic numbers also in digits other languages like Arabic, Hebrew, Thailand then you need to use one of the methods in the Character class.
If the data are not already verified then you should also add an error handling.Volker Berlin
www.inetsoftware.de
 09262010, 08:51 AM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
 09262010, 09:03 AM #6Member
 Join Date
 Sep 2010
 Posts
 33
 Rep Power
 0
This is the typical confusion between Arabic numbers and Arabic digits.
Arabic digits are '٠' ... '٩' and Latin Numbers are '0' ... '9'. Both are Arabic Numbers. But the Arabic people named it India numbers. If you was ever in any Arabic country then you will see that on the products (water, chocolate, etc. ) overall are Arabic digits and not Latin digits. The Arabic digits look more like the Arabic letters. Else the Latin digits look like more Latin Letters.
This all has noting to do with the roman numbers.
Edit: My browser (Firefox) show first the Arabic 9 and then Arabic 0. But this is wrong. The Arabic Digits will written in the same order like Latin. Only the Arabic Letters are written from right to left.Last edited by Horcrux7; 09262010 at 09:06 AM.
Volker Berlin
www.inetsoftware.de
 09262010, 10:24 AM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
It's more complex than that: there are the 'Eastern Arabic Numerals' and the 'Western Arabic Numerals' (the stuff we use); I was talking about the latter; also read this link.
kind regards,
Jos
Similar Threads

URLConnection Efficiency
By Lil_Aziz1 in forum New To JavaReplies: 22Last Post: 08192010, 06:27 PM 
question about connection efficiency in database
By mr_anderson in forum JDBCReplies: 7Last Post: 07292010, 11:25 AM 
An Efficiency Question
By Revenna in forum Java 2DReplies: 0Last Post: 06252010, 07:22 AM 
How do I improve the background image efficiency?
By martypapa in forum Java 2DReplies: 2Last Post: 02102010, 08:00 PM 
method efficiency
By TheWave in forum Advanced JavaReplies: 0Last Post: 02132008, 05:11 AM
Bookmarks