Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- // write your code here
- }
- public static int addLenghtsExceptS(ArrayList<String> list)
- {
- int length = 0;
- for (int i = 0; i < list.size(); i++)
- {
- if (!list.get(i).startsWith("s"))
- {
- length += list.get(i).length();
- }
- }
- }
- public static String findMin(ArrayList<Person> list) {
- Person youngestPerson = new Person("Jim". 0);
- //Assuming this object has a public constructor for this solution.
- //If the object does not, a different solution can be found below.
- for (int i = 0; i < list.size(); i++)
- {
- if (list.get(i).getAge() < youngestPerson.getAge())
- {
- //Reference type. Pointer to the original object created in the list.
- youngestPerson = list.get(i);
- }
- }
- return youngestPerson.getName();
- }
- public static String findMin(ArrayList<Person> list) {
- int youngestAge;
- int youngestName;
- //Assuming this object has a public constructor for this solution.
- //If the object does not, a different solution can be found below.
- for (int i = 0; i < list.size(); i++)
- {
- if (list.get(i).getAge() < youngestAge)
- {
- //Reference type. Pointer to the original object created in the list.
- youngestAge = list.get(i).getAge();
- youngestName = list.get(i).getName();
- }
- }
- return youngestName;
- }
- public static void removeFirstLettersAndInsertFun(ArrayList<String> list)
- {
- for(int i = 0; i < list.size(); i++)
- {
- list.set(i, list.get(i).substring(1));
- }
- //Arraylist has a generic override of the add() method that permits specifying an index.
- //Subtract 2 because the list indicies start at zero, and you also want the second to last element.
- list.add(list.size() - 2,"fun");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement