Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to modify System.arraycopy ?

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to modify System.arraycopy ?

    public static native void arraycopy(Object src, int src_position,  
                                            Object dst, int dst_position,  
                                            int length);


    My object contain two parameters (int x, char y)

    i want to increment all "x" elements each time i copy my array .

    actually i copy with O(n) and next i increment with also O(n) this decrease the performance !!!

    if we can modifiy arraycopy to copy and increment element by element the complexity will be O(n).


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to modify System.arraycopy ?

    The complexity however you do it is O(n) - you've got to loop over the array somehow.

    if we can modifiy arraycopy to copy and increment element by element
    Systems.arraycopy is native

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: How to modify System.arraycopy ?

    Just to back up copeg's points about the O(n),

    If you look at the way you listed it, it was going to be O(2n), in Big-O notation we are not interested in that 2 as it is insignificant. Thus as copeg pointed out it will still be O(n)! He is quite right saying that it will also be O(n) best case.

    Chris

Similar Threads

  1. add and increment array elements by arraycopy
    By MMD in forum Collections and Generics
    Replies: 7
    Last Post: May 8th, 2013, 03:23 PM
  2. How can i modify this to work ?
    By steven_bishop in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2012, 07:45 PM
  3. Having Trouble Modify the code!!
    By jehov86 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 2nd, 2012, 09:42 AM
  4. How to modify System.out.println()
    By emailkia in forum Java Theory & Questions
    Replies: 6
    Last Post: April 25th, 2011, 12:40 AM
  5. Modify Colors in a Picture
    By theuniverse in forum Java Theory & Questions
    Replies: 0
    Last Post: October 17th, 2009, 04:49 PM