Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1

    Default java array problem


    what is the best way to learn java array ...ok ra ko basta one dimensional pero when it comes to mutiple dimensional array ma yabag ko... i need ur advice mga programmer...still a student ...and want to learn more on programming...unsa best book nga reference or ebooks ba nga angay study han ug methods sad mag libog ko gamay basta e pasa sa lain nga class...

  2. #2
    Post nalng diri imong nalibgan bro, and regarding sa book sa ako lang ok kaayo ang "Java how to program" by Deitel, thick book almost ma cover gyud tanan basics-intermediate java, and lots of programming tips..

  3. #3
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    initializing

    Object[][] doubleArray = new Object[4][5];

    pede sad

    int x=3;
    int y=2;
    Object[][] doubleArray = new Object[x][y];

    pede sad ni... but wala na ko sure;

    Object[][] doubleArray = {{"ngano","mani"},{"baboy","ka"}};

    scanning an array

    normal loop

    code

    for(int x=0;x<doubleArray.length;x++){
    Object[] row = doubleArray[x];
    for(int y=0;y<row.length;y++){
    Object value = row[y];
    System.out.println(x+","+y+" => "+value);
    }
    }

    output using array above
    0,0 => ngano
    0,1 => mani
    1,0 => baboy
    1,1 => ka


    *** newer type of loop w same output
    int x=0;
    int y=0;
    for(Object[] row : doubleArray){
    for(Object value : row){
    System.out.println(x+","+y+" => "+value);
    y++;
    }
    x++;
    }


    well the point is double loops...

  4. #4
    any other idea mga bro ako kalibgan kanha pag excute ug array using methods/class ...mag libog ko kung multideminsional nah...any other idea...

  5. #5
    igo ra gud ko mag tagna2x kung multi-dimensional na gud

  6. #6
    Quote Originally Posted by skeptic_rob View Post
    any other idea mga bro ako kalibgan kanha pag excute ug array using methods/class ...mag libog ko kung multideminsional nah...any other idea...
    Assignment na ninyo brad? Usahay libug-libugun gyud ta sa mga maestro no.

    In actual work, it's very seldom that you are faced with the need of multi-dimensional arrays in Java - unlike in PHP. In Java you have objects and objects can be stored in lists/arrays. Your objects can also hold lists & arrays.

    So in actual work, if you find yourself battling with multi-dimensional arrays in Java, then that's a red flag for you that you're doing something wrong. Your code must be as simple and possible no matter how complex the requirements are.

    ---

    Anyway, you need to read about the Collections framework sa Java. They gave us this wonderful framework so you wouldn't have to use those horrible multi-dimensional arrays like in PHP (again - sorry folks).

    In my experience, multi-dimensional arrays are so error-prone that it makes things very very hard to maintain, specially with complex requirements. It makes things coupled and not flexible. Stay away from them as much as possible.

  7. #7
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    Quote Originally Posted by skeptic_rob View Post
    any other idea mga bro ako kalibgan kanha pag excute ug array using methods/class ...mag libog ko kung multideminsional nah...any other idea...
    una...

    loops are primitive so you cannot contain or break them down between classes or methods

    you are using arrays because you are going to handle many instances of one kind of Object

    sample

    Integer[][] doubleIntegerArray = new Integer[5][4];

    meaning naa ka integer array with 5 rows and 4 columns...pede rasad bali bali

    Always remember containers ra na ang array
    each instance of an object sulod sa array is unique thus kung ganahan ka mutawag og command sa usa ka instance either you isolate the instance by...

    Integer singleInstance = doubleIntegerArray[0][0]; => first element ni...in this case null...kay wala man nato sudli atong array

    though you don't have to put it in another variable...

    sample ako sudlan ang first element og

    doubleIntegerArray[0][0] = 1; (dili ni allowed sa older version of java because of lack of "Autocast")

    doubleIntegerArray[0][0] = new Integer(1); (same ra ni og buhat sa taas pero dili ka maproblema kung kulang sa version imong java)

    pwede na ka muingon og

    double dblValue = doubleIntegerArray[0][0].doubleValue(); Yey ako gamit method sa integer...after akong natarung og point out nga ang ganahan nako nga element kay ang naa sa first (0) row or first (0) column.

  8. #8
    @ts
    na answer naka ni Klave and what maddox22 said is true as well. in actual work (java), there will be few instances where you'll need to use arrays instead of collection objects but since you are a student you cannot do away with arrays for now

    this here is as good a starting java book as any. even if you're new to oop. it's downloadable and free. just start at the beginning and re-read if you must until you get that eureka moment
    The Java™ Tutorials

  9. #9
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    Quote Originally Posted by devnull View Post
    @ts
    na answer naka ni Klave and what maddox22 said is true as well. in actual work (java), there will be few instances where you'll need to use arrays instead of collection objects but since you are a student you cannot do away with arrays for now

    this here is as good a starting java book as any. even if you're new to oop. it's downloadable and free. just start at the beginning and re-read if you must until you get that eureka moment
    The Java™ Tutorials
    in fairness ako ginamit na collections kay List ra gyud og Vector, Arrays kay gamay ra og gamit unya kinaraan na ayu...

  10. #10
    cge lang mo post dinhi guys about inyu idea....later on or little by little i will learn about ur post dinhi

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. java - stack() problem
    By akocdiego in forum Programming
    Replies: 12
    Last Post: 07-08-2013, 10:43 PM
  2. Replies: 16
    Last Post: 04-21-2012, 11:26 PM
  3. Help in java. Arrays
    By jairoh_ in forum Programming
    Replies: 25
    Last Post: 02-03-2012, 07:48 PM
  4. java problem..
    By wongfeihong in forum Programming
    Replies: 81
    Last Post: 09-26-2010, 10:56 AM
  5. Got Java, PHP, C, MySQL problem?
    By abstracted in forum Programming
    Replies: 11
    Last Post: 06-25-2010, 09:36 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
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top