Advertisement
Guest User

arraylist

a guest
Oct 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package ossm.manicom.sadie.arraysandlists;
  2. import java.util.*;
  3. public class arraylistClass implements customList
  4. {
  5.  
  6. private Object[] myKeep;
  7. private int arrSize = 0;
  8.  
  9. public arraylistClass()
  10. {
  11. myKeep = new Object[10];
  12. }
  13. public int Size()
  14. {
  15. return arrSize;
  16. }
  17.  
  18. public void Add(Object obj)
  19. {
  20. if(myKeep.length <= 5)
  21. {
  22. IncreaseListSize();
  23. }
  24. myKeep[arrSize++] = obj;
  25. }
  26.  
  27. public Object Get(int index)
  28. {
  29. if(index < arrSize)
  30. {
  31. }
  32. return index;
  33. }
  34.  
  35.  
  36. public Object Delete(int index)
  37. {
  38. if(index < arrSize)
  39. {
  40. Object obj = myKeep[index];
  41. myKeep[index] = null;
  42. int temp = index;
  43. while(temp < arrSize)
  44. {
  45. myKeep[temp] = myKeep[temp + 1];
  46. myKeep[temp + 1] = null;
  47. temp++;
  48. }
  49.  
  50. arrSize--;
  51. return obj;
  52. }
  53. return index;
  54. }
  55.  
  56.  
  57. public void IncreaseListSize()
  58. {
  59. myKeep = Arrays.copyOf(myKeep, myKeep.length *2);
  60. }
  61.  
  62. public static void main(String[] args)
  63. {
  64. arraylistClass mal = new arraylistClass();
  65. mal.Add(new Integer(2));
  66. mal.Add(new Integer(5));
  67. for(int i=0; i<mal.Size(); i++)
  68. {
  69. System.out.println(i);
  70. }
  71. }
  72.  
  73. @Override
  74. public void prepend(Object obj) {
  75. // TODO Auto-generated method stub
  76.  
  77. }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement