Posts

Showing posts from December, 2018

Arrays Programming Examples in Java - Part 2

Image
List of Java Array Programs - Part 2 ----------------------------------- 8. Find the Size of an Array. 9. Find Even and Odd in Array. 10. Find PRIME number in Array. 11. Increase each Array elements size by 1 . 12. Check Array contains the specific value. 13. Create Array List from Array . 14. Find Duplicate Using Brute Force Method. 15. Find Duplicate Using HashSet. 16. Remove Duplicates in Array using Set (HashSet). ----------------------------------- public class ArrayProgramsPart2 {  public static void main(String[] args) {   int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };   String[] s = { "Java", "C", "Java", "C", "NODDY", "SELENIUM", "AUTOTECHX" };   SizeOfArray(a);   EvenOdd(a);   PrimeNumber(a);   IncreaseArrayBy1(a);   ArrayContains(s);   CreateArrayListFromArray(s);   FindDuplicateUsingBruteForceMethod(s);   FindDuplicateUsingHashSet(s);   RemoveDuplic

Arrays in Java

Image
What are Java Array? Array is an Indexed Collection of Fixed Number of Homogeneous/Similar Data Elements . int[ ] x = new int[5]; Example: Valid   Array Examples: int[ ] arr1=new int[5]; int arr2[ ]=new int[5]; int [ ]arr3=new int[5]; int[ ] arr4 = new int[ ]{10,20,30,40,50}; int[ ] arr5 = {10,20,30,40,50}; Arrays can be initialized when they are declared. The array will automatically be created large enough to hold the number of elements you specify in the array initializer. There is  no  need to use  new . public static void main(String args[]) {    int month_days[ ];     month_days = new int[12];     month_days[0] = 31;     month_days[1] = 28;     month_days[2] = 31;     month_days[3] = 30;     month_days[4] = 31;     month_days[5] = 30;     month_days[6] = 31;     month_days[8] = 30;     month_days[9] = 31;     month_days[10] = 30;     month_days[11] = 31;      System.out.println(&quo