Custom Collection Development Part 2 | Core Java Tutorial | Mr. Hari Krishna

Java

Video is ready, Click Here to View ×


Custom Collection Development Part-2
Internal Algorithm for Increasing Capacity Collection
(Code for solving Array Size Problem)

** For Online Training Registration: https://goo.gl/r6kJbB ► Call: +91-8179191999

► Visit Our Website for Classroom Training:

Core Java Training

Video is ready, Click Here to View ×

► For Online Training:
https://nareshit.com/course/core-java-online-training/

————————–

► About NareshIT:

“Naresh IT is having 14+ years of experience in software…

20 thoughts on “Custom Collection Development Part 2 | Core Java Tutorial | Mr. Hari Krishna

  1. public class Test {

    Object objarr[]=new Object[10];
    public int elementCount=0;

    public void add(Object obj){

    if(elementCount==objarr.length){

    incrementCapacity();
    }

    objarr[elementCount]=obj;
    elementCount++;

    }
    private void incrementCapacity() {
    // TODO Auto-generated method stub
    int newCapacity=objarr.length*2;

    Object nextArray[]=new Object[newCapacity];
    for(int i=0;i<objarr.length;i++){

    nextArray[i]=objarr[i];
    objarr=nextArray;
    }
    }

    private void getArrayElement() {
    // TODO Auto-generated method stub

    for(int i=0;i<objarr.length;i++){

    System.out.println(objarr[i]);
    }

    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    Test test=new Test();
    test.add("a");
    test.add('b');
    test.add(10);
    test.add(7.5);
    test.add(8);
    test.add(9);
    test.add(10);
    test.add("sachin");
    test.add("a");
    test.add("hello");
    test.add("11");
    test.add("12");
    test.add("13");
    test.getArrayElement();
    System.out.println("Successfully retrieved");
    }

    }

  2. Hello thanks for the video. i have two questions.

    1) here we are trying to solve the problem of size because we may need more space dynamically. but we are adding here elements by calling add method 10 times for 10 objects. but what about runtime?, we cant add runtime here everytime we will need to modify code to add elements. what if we have 50 elements is it feasible to call add method 50 times?

    2)what if once the 10 spots are filled for the first time we want to add only 2 more numbers but here we are creating more 10 spaces so 8 spaces wasted right?

    i have created a code and it is working with dynamically increasing space without code change please reply if it is correct.

    package new1;

    import java.util.Scanner;

    public class Custom_Collection_overcoming_size {

    public static void main(String[] args) {

    Scanner s=new Scanner(System.in);
    System.out.println("how many numbers");
    int l1=s.nextInt();
    Object[] h=new Object[l1];
    System.out.println("Enter the elements");
    for(int i=0;i<l1;i++)
    {

    h[i]=s.nextInt();
    }
    System.out.println("Exceeded limit want to enter more?");
    char ch=s.next().charAt(0);
    if(ch=='y')
    {

    System.out.println("how much more");
    int l2=s.nextInt();
    int l3=l1+l2;
    Object[] h1=new Object[l3];
    for(int k=0;k<l1;k++)
    {
    h1[k]=h[k];
    }
    System.out.println("please enter more");
    for(int t=l1;t<l3;t++)
    {
    h1[t]=s.nextInt();
    }
    System.out.println("Your array");
    for(Object p:h1)
    {
    System.out.println(p);
    }
    }
    else
    {
    for(Object j:h)
    {
    System.out.println(j);
    }
    }
    }

    }

  3. sir u are one of the best teacher,sir but whatever written is not visible clearly ,also upload videos on real time examples of multithreading and also more and more video if possable on every topics of java ,becoz whatever u teach is amazing.

  4. excellent teaching sir g .Thank you very much Hari krishna sir.and one more request sir please after completing all collection videos sir it a Request sir please start for GUI part in core java with awt and swing .please sir please.start kardo sir .Mana mat karna sir please. taki sir ham ek core java ma acha sa project Bana sake sir please.and sir please post the video daily otherwise sir link is broken .

Leave a Reply

Your email address will not be published. Required fields are marked *