package com.javainhouse;
import java.util.ArrayList;
public class RemoveDuplicates {
public static void main(String[] args)
{
ArrayList<Object> al = new ArrayList<Object>();
al.add("java");
al.add('a');
al.add('b');
al.add('a');
al.add("java");
al.add(10.3);
al.add('c');
al.add(14);
al.add("java");
al.add(12);
System.out.println("Before Remove Duplicate elements:"+al);
for(int i=0;i<al.size();i++)
{
for(int j=i+1;j<al.size();j++)
{
if(al.get(i).equals(al.get(j)))
{
al.remove(j); j--;
}
}
}
System.out.println("After Removing duplicate elements:"+al);
}
}
|
Home » Posts filed under remove
Java Program To Remove Duplicate Elements From ArrayList without using Collections
in
arrayList,
collection,
elements,
Java,
java program,
java programming,
remove
- on 11:47:00
- No comments
Program to remove a particular character from a sentence
in
interview questions,
Java,
java program,
java programming,
particular character,
remove,
sentence
- on 03:06:00
- No comments
public class Test
{
public static void main(String[] args)
{
String test=null;
char remove = 0;
System.out.println("Enter the String");
test = new Scanner(System.in).nextLine();
System.out.println("Enter the Character to be removed");
remove=new Scanner(System.in).nextLine().charAt(0);
StringBuilder newstring =new StringBuilder();
for (int i = 0; i < test.length(); i++)
{
if(remove==test.charAt(i))
{
continue;
}
newstring.append(test.charAt(i));
}
System.out.println(newstring);
}
}
{
public static void main(String[] args)
{
String test=null;
char remove = 0;
System.out.println("Enter the String");
test = new Scanner(System.in).nextLine();
System.out.println("Enter the Character to be removed");
remove=new Scanner(System.in).nextLine().charAt(0);
StringBuilder newstring =new StringBuilder();
for (int i = 0; i < test.length(); i++)
{
if(remove==test.charAt(i))
{
continue;
}
newstring.append(test.charAt(i));
}
System.out.println(newstring);
}
}