"உண்மையில் பயனுள்ளவற்றுடன் நான் எப்படி தொடங்குவது? வரிசைப்பட்டியல் மற்றும் ஜெனரிக்ஸ் வேலை செய்யக்கூடிய இரண்டு வழிகளை நீங்கள் இப்போது காண்பீர்கள்:"

"எடுத்துக்காட்டு 1:"

விசைப்பலகையில் எண்களின் பட்டியலைப் படிக்கவும்
public static void main(String[] args) throws IOException
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in) );
    ArrayList<Integer> list = new ArrayList<Integer>() ;

    while (true)
    {
        String s = reader.readLine();
        if (s.isEmpty()) break;
        list.add(Integer.parseInt(s));
    }
}

"எடுத்துக்காட்டு 2:"

மேலே உள்ளதைப் போலவே, ஆனால் பட்டியலின் முடிவில் இரட்டைப்படை எண்கள் சேர்க்கப்படும்.
public static void main(String[] args) throws IOException
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    ArrayList<Integer> list = new ArrayList<Integer>();

    while (true)
    {
        String s = reader.readLine();
        if (s.isEmpty()) break;

        int x = Integer.parseInt(s);
        if (x % 2 == 0)  // Check that the remainder is zero when we divide by two
            list.add(x);         // Add to the end
        else
            list.add(0, x);      // Add to the beginning
    }
}

"எடுத்துக்காட்டு 3:"

5 ஐ விட பெரிய அனைத்து எண்களையும் நீக்கு:
public static void main(String[] args) throws IOException
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in) );
    ArrayList<Integer> list = new ArrayList<Integer>();

    list.add(1);
    list.add(7);
    list.add(11);
    list.add(3);
    list.add(15);

    for (int i = 0; i < list.size(); ) // We moved the statement that increases i to inside the loop
    {
        if (list.get(i) > 5)
            list.remove(i);  // Don’t increase i if we deleted the current element
        else
            i++;
    }
}

"எடுத்துக்காட்டு 4:"

ஒரு வரிசையை இரண்டு பகுதிகளாகப் பிரிக்கவும் - இரட்டை மற்றும் இரட்டை எண்கள்
public static void main(String[] args) throws IOException
{
    // Static initialization of the array
    int[] data = {1, 5, 6, 11, 3, 15, 7, 8};

    // Create a list where all elements are Integers
    ArrayList<Integer> list = new ArrayList<Integer> ();

    // Use the array to fill the list
    for (int i = 0; i < data.length; i++) list.add(data[i]);

    ArrayList<Integer> even = new ArrayList<Integer>();  // Even numbers
    ArrayList<Integer> odd = new ArrayList<Integer>();    // Odd numbers

    for (int i = 0; i < list.size(); i++)
    {
        Integer x = list.get(i);
        if (x % 2 == 0)    // If x is even
            even.add(x);   // Add x to the collection of even numbers
        else
            odd.add(x);    // Add x to the collection of odd numbers
    }
}
2
பணி
Java Syntax,  நிலை 7பாடம் 8
பூட்டப்பட்டது
Code entry
Your attention, please! Now recruiting code entry personnel for CodeGym. So turn up your focus, let your fingers relax, read the code, and then... type it into the appropriate box. Code entry is far from a useless exercise, though it might seem so at first glance: it allows a beginner to get used to and remember syntax (modern IDEs seldom make this possible).

"எடுத்துக்காட்டு 5:"

பட்டியல்களை ஒன்றிணைக்கவும்
public static void main(String[] args) throws IOException
{
    ArrayList<Integer> list1 = new ArrayList<Integer>();   // Create a list
    Collections.addAll(list1, 1, 5, 6, 11, 3, 15, 7, 8);   // Fill the list

    ArrayList<Integer> list2 = new ArrayList<Integer>();
    Collections.addAll(list2, 1, 8, 6, 21, 53, 5, 67, 18);

    ArrayList<Integer> result = new ArrayList<Integer>();

    result.addAll(list1);   // Add all values from each list to the new list
    result.addAll(list2);

    for (Integer x : result)   // A fast way to loop over all elements, only for collections
    {
        System.out.println(x);
    }
}

"கூல்! டியாகோ இப்போது எனக்கு ஒரு டிரக் லோடு இதே போன்ற பயிற்சிகளைக் கொடுப்பாரா?"

"ஆம், அவர் செய்வார்."