Click here to Skip to main content
15,908,111 members
Home / Discussions / Java
   

Java

 
AnswerRe: How to Delete/remove index elements in 2D arrayList Pin
Richard MacCutchan10-Apr-12 5:38
mveRichard MacCutchan10-Apr-12 5:38 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
B.Bryce10-Apr-12 7:11
B.Bryce10-Apr-12 7:11 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
Richard MacCutchan10-Apr-12 8:27
mveRichard MacCutchan10-Apr-12 8:27 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
TorstenH.10-Apr-12 19:20
TorstenH.10-Apr-12 19:20 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
Nagy Vilmos11-Apr-12 2:07
professionalNagy Vilmos11-Apr-12 2:07 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
TorstenH.11-Apr-12 3:54
TorstenH.11-Apr-12 3:54 
AnswerRe: How to Delete/remove index elements in 2D arrayList Pin
BobJanova11-Apr-12 1:09
BobJanova11-Apr-12 1:09 
AnswerRe: How to Delete/remove index elements in 2D arrayList Pin
Nagy Vilmos11-Apr-12 2:06
professionalNagy Vilmos11-Apr-12 2:06 
Your code could almost work.
First find the element, then remove it. Good practice is to never remove items from list while iterating through it and once you locate the required item to break.

Java
public class DisplayArrayList {
 
    public static void main(String[] args) throws Exception {
        List<Employee> list = new ArrayList<Employee>();
        list.add(new Employee(1, "A","Delhi"));
        list.add(new Employee(2, "B","Mumbai"));
        list.add(new Employee(3, "C","Chennai"));
        list.add(new Employee(4, "D","Kolkata"));
         System.out.println(" ");
        System.out.print("Enter Employee Id: ");
        Scanner input=new Scanner(System.in);
        int id = input.nextInt();
        Employee del = null;
        for (Employee s : list) {
            if(id == s.getId()) {
                del = s;
                break;
            }
        }

        if (del != null) {
            System.out.println("Name and Address of employee is: ");
            System.out.print(s.getName()+" " +s.getAddress());
            list.remove(del);
        }
    }
}



Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
TorstenH.11-Apr-12 3:57
TorstenH.11-Apr-12 3:57 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
Nagy Vilmos11-Apr-12 3:59
professionalNagy Vilmos11-Apr-12 3:59 
Questionjava SmS Application...... Pin
fahad479-Apr-12 19:59
fahad479-Apr-12 19:59 
AnswerRe: java SmS Application...... Pin
Anil Kumar 231-Jul-12 21:43
Anil Kumar 231-Jul-12 21:43 
QuestionSplitting one string Pin
Ejii8-Apr-12 21:27
Ejii8-Apr-12 21:27 
AnswerRe: Splitting one string Pin
Richard MacCutchan8-Apr-12 21:43
mveRichard MacCutchan8-Apr-12 21:43 
AnswerRe: Splitting one string Pin
Ejii8-Apr-12 22:27
Ejii8-Apr-12 22:27 
Questiononline shopping application in Java Pin
Member 87135148-Apr-12 20:30
Member 87135148-Apr-12 20:30 
AnswerRe: online shopping application in Java Pin
Richard MacCutchan8-Apr-12 21:41
mveRichard MacCutchan8-Apr-12 21:41 
AnswerRe: online shopping application in Java Pin
TorstenH.9-Apr-12 19:35
TorstenH.9-Apr-12 19:35 
Questionencryption technique Pin
AnkitGujjar7-Apr-12 18:53
AnkitGujjar7-Apr-12 18:53 
AnswerRe: encryption technique Pin
Richard MacCutchan8-Apr-12 6:06
mveRichard MacCutchan8-Apr-12 6:06 
Questionjava socket program that delete add tem files Pin
zahidaa6-Apr-12 9:42
zahidaa6-Apr-12 9:42 
AnswerRe: java socket program that delete add tem files Pin
Richard MacCutchan6-Apr-12 10:02
mveRichard MacCutchan6-Apr-12 10:02 
GeneralRe: java socket program that delete add tem files Pin
zahidaa7-Apr-12 5:44
zahidaa7-Apr-12 5:44 
GeneralRe: java socket program that delete add tem files Pin
Richard MacCutchan7-Apr-12 6:38
mveRichard MacCutchan7-Apr-12 6:38 
Questionformat and partition drive Pin
Jameson B5-Apr-12 18:11
Jameson B5-Apr-12 18:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.