Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: 2 Method Problem

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 2 Method Problem

    I'm trying to modify my list by updating it and finding the last name. How can I rewrite my last 2 methods to do that.




    import java.util.ArrayList;

    public class DataCollection {

    ArrayList<Person> list = new ArrayList<>();



    Person newName = new Person(10,"aas","gym","798",876-123);



    Person p1 = new Person(11,"aaa", "gina","654",911-911);
    Person p2 = new Person(12, "persia","weee","546",324);


    public void add(Person person) {
    list.add(person);
    }

    public int remove(String lastName) {
    for (int i = 0; i < list.size(); i++) {
    Person person = list.get(i);
    if (person.getLastName().equals(lastName)) {
    list.remove(person);
    }
    }

    public int update(String lastName, String newName){
    Person person;
    for (int i = 0; i < list.size(); i++) {
    person = list.get(i);
    if (person.lastName != person.){
    Person.setLastName(newName);


    }
    public Person find (String lastName){
    Person person;
    for (int i = 0; i < list.size(); i++) {
    person = list.get(i);
    if (person.lastName.equals(lastName)) {
    System.out.print(lastName);
    }
    }
    }
    }
    }
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: 2 Method Problem

    modify my list by updating it and finding the last name.
    What problems are you having with the posted code?
    Copy and paste here the full text of any error messages/
    If the results are not what you want, show the current results and explain what you want in place of that.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Problem with method
    By Slapy in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 8th, 2013, 12:30 PM
  2. I have problem with method in Java
    By bheemudu.neeli@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 2nd, 2013, 02:54 AM
  3. Method problem
    By skeptile2 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 7th, 2013, 03:16 AM
  4. Looping method problem.
    By Swen in forum What's Wrong With My Code?
    Replies: 24
    Last Post: December 29th, 2011, 09:49 AM
  5. problem with Scanner nextLine() method
    By mia_tech in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 10th, 2009, 04:14 AM

Tags for this Thread