Coder Social home page Coder Social logo

java-tasks's Introduction

java-tasks

These are all java tasks that I created during studying programming fundamentals subject.

fun fact ๐Ÿ˜‚

In the above Java files, there is a file SarmadiList.java.

story behind SarmadiList.java

When we studied Arrays in Java, we came to know that in Java the length of Arrays is immutable (fixed). And we cannot append any item to Arrays in Java as we do in Lists in Python.

At that time I created a method in Java that takes two arguments and returns a new array.

  1. 1st Argument is an Array in which I want to insert another entry.
  2. 2nd Argument is a Number that I want to insert at the end.
public static int[] append(int[] list, int value) {
    int[] newList = new int[list.length + 1];
    for (int i = 0; i < list.length; i++) {
        newList[i] = list[i];
    }
    newList[newList.length - 1] = value;
    return newList;
}

What it does is that it creates a new Array with the length of 1+ in the length of the previous Array. After that, it inserts all the values of a previous Array into the new Array, and the number that it takes as a 2nd argument is inserted at the last index of the new Array. Finally, it returns the new Array.

After doing this, I felt like I conquered something ๐Ÿคฃ.

what I learned โœจ

When I show this to my teacher, he told me that by doing this I am creating a new Array in memory and not appending it at the end of that previous Array, which is not memory efficient.

java-tasks's People

Contributors

msarmadqadeer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.