Rakisingathi
String question
2 Answer(s)      a year and 9 months ago
Posted in : Java Interview Questions

which method is used in java to eliminate the duplicate elements in String?

View Answers

August 23, 2011 at 11:23 AM


import java.util.*;
class RemoveDuplicates{
public static void main(String[] args){
String[] str = new String[] {
"Where",
"there",
"is",
"will",
"there",
"is",
"a",
"way"};

Arrays.sort(str);

int k = 0;

for (int i = 0; i < str.length; i++){
 if (i > 0 && str[i].equals(str[i -1]))
  continue;
  str[k++] = str[i];
 }
 String[] st = new String[k];
 System.arraycopy(str, 0, st, 0, k);
 for (int i = 0; i < st.length; i++)
 System.out.println(st[i]);
}
}

August 23, 2011 at 11:23 AM


import java.util.*;
class RemoveDuplicates{
public static void main(String[] args){
String[] str = new String[] {
"Where",
"there",
"is",
"will",
"there",
"is",
"a",
"way"};

Arrays.sort(str);

int k = 0;

for (int i = 0; i < str.length; i++){
 if (i > 0 && str[i].equals(str[i -1]))
  continue;
  str[k++] = str[i];
 }
 String[] st = new String[k];
 System.arraycopy(str, 0, st, 0, k);
 for (int i = 0; i < st.length; i++)
 System.out.println(st[i]);
}
}









Related Pages:
String question
String question  which method is used in java to eliminate the duplicate elements in String?   import java.util.*; class RemoveDuplicates{ public static void main(String[] args){ String[] str = new String[] { "Where
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
string related question
string related question  *q.1>how i dispaly the reference of string variableS ? eg:-String s1="my name"; Sring s2="your name"; here what is address of variable s1 and s2
Question?
Question?  My question is how to: Add a menu bar to the program...]; String winningsString = "The winning numbers are: "; String... static void main(String[] arguments) { JLottery2 lotFrame = new JLottery2
Question
Question  Sir, give me a java program to count the number of tokens , given a string and a seperator
question
;import java.util.*; class Student{ String name; int marks1; int marks2; int marks3; int average; Student(String name,int marks1,int...; } public String getName(){ return name; } public int getMarks1
question
(); } return true; } User Name: Password: <%String st..." import="java.sql.*"%> Insert title here <% String userNam, userName; String passwd, userPass; PreparedStatement ps; //String name=new
question
javax.swing.text.MutableAttributeSet; public class Original { public static void main(String[] args...(); String urlString = (String)urlStack.peek...) { // System.out.println(url.getText()); String strUrl = url.getText
Question
MysqlConnect{ public static void main(String[] args) { System.out.println("MySQL
question
)form2.jsp: <% String name=request.getParameter("name"); String address
question
extends JFrame{ public static void main(String[]args){ JFrame
question
; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated
java fundamental question related to string
java fundamental question related to string  public class Myclass { Public static void main(String args[]) { String s=â??helloâ??; StringBuffer sb=new StringBuffer(s); Sb.reverse(); If(s==sb) system.out.println(â??aâ
Question in Eclipse
Question in Eclipse   ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square... that computes the area of a Square. 7.A toString method that will return a String
Question in Eclipse ??
Question in Eclipse ??  ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square... that computes the area of a Square. 7.A toString method that will return a String
Question in eclipes ??!!
Question in eclipes ??!!  Hooole EveryOne I have Question in eclipes !!? Question is : The objectives of this lab are 1.Using the ââ?¬Å? thisÃ... the imaginary part of the left operand.). 7.A toString method that will return a String
STRING FUNCTIONS
STRING FUNCTIONS  HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS... a string and 2 integers from user. It then changes the case of characters at those... String removeCharAt(String s, int pos) { StringBuffer buf = new StringBuffer
java question :)
java question :)  write java program to use vector in ArrayList with add, remove,sort   import java.util.Vector; public class RemoveVectorElement { public static void main(String[] args) { Vector<String>
Question of apatten
Question of apatten  Welcome EveryOne , I have the progrem of apatten... void main(String[]args){ displaypattern(7); } public static void... pattern { public static void main(String[]args){ displaypattern(7
Netbeans Question.
Netbeans Question.   Ok here is my code- * * To change this template, choose Tools | Templates * and open the template in the editor. */ import... the command line arguments */ public static void main(String[] args) { Random randomNumber
interview question
TakeAndReturnObject{ public static String getLargestWord(String st){ String[] str = st.split(" "); String longest = str[0]; for(String s : str){ if(s.length() >...(String[] args){ String str="All glitters are not gold"; String longestword
C# question
C# question  In C#, string is a class or primitive type. Explain
java question
java question  i have a string like "My name is arvind.i live in bangalore.i study in college.".the problem is that i hav to break this string into three seperate lines
gui question
a string from the user in a textfeild and print using option pane whether... static void main(String[] args){ JFrame f=new JFrame(); JLabel label=new JLabel("Enter String: "); final JTextField text=new JTextField(20
java question
information based on id . class employee { int id; String name; String State; String City; String Area; } Now i need to display **employee name** based on state ,city... = new ArrayList<Employeelookup>(); int id; String name; String State
java question
information based on id . class employee { int id; String name; String State; String City; String Area; } Now i need to display **employee name** based on state ,city... = new ArrayList<Employeelookup>(); int id; String name; String State
swing question
){ String value1=text1.getText(); String value2=text2.getText(); try...+"'"); String uname="",pass=""; if(rs.next()){ uname... main(String arg[]){ new LoginDemo(); } } class NextPage extends JFrame
servlet question
="java.io.*" %> <%@ page import="java.sql.*" %> <% String saveFile=""; String contentType = request.getContentType(); if ((contentType != null) &...; } String file = new String(dataBytes); saveFile = file.substring(file.indexOf
jsp question
ServletException,IOException { String name=req.getParameter("name"); String address=req.getParameter("address"); String con=req.getParameter("contact"); String email=req.getParameter("email
java Question
width and height . *A string data field named color that specified the color
java Question
width and height. A string data field named color that specified the color
programing question
[i]); } add(panel); setVisible(true); pack(); } public static void main(String
question for "get method"
question for "get method"  when I want make method "get" for name or any char or string ..how I can write the syntax ? and what does it return
Core Java Interview Question, Interview Question
state when it blocks on I/O. Question: To what value is a variable of the String... Core Java Interview Question Page 14       Question: What is clipping? Answer: Clipping
Core Java Interview Question, Interview Question
value to a String? Answer: The result is a String object. Question: What... Core Java Interview Question Page 21       Question: How are the elements of a GridLayout
Core Java Interview Question, Interview Question
Core Java Interview Question   ....   Core Java Interview Question Page 1 How could Java... to a file?      Core Java Interview Question Page 2
String Array - Java Beginners
String Array  Thanks for the help you had provided,,, Your solution did worked... I worked on the previous solution given by you and it worked.... I am able to solve the question with that, that's in front of me..... Thanks
Core Java Interview Question, Interview Question
add a double value to a String? Answer: The result is a String object. Question... Core Java Interview Question Page 23       Question: To what value is a variable
NSMutableArray Search String
NSMutableArray Search String  Hi all, In my iPhone SDK application.. i wanted to search from the table data. My question is ..do i need to innsert the table data into search array? thanks
String Methods - Java Beginners
String Methods  Greetings RoseIndia Team; Thank you for your prompt response to my question. I have one other question requiring your assistance... main(String []args){ Scanner scanner = new Scanner(System.in
Core Java Interview Question, Interview Question
. Question: Is "abc" a primitive value? Answer: The String literal "abc" is not a primitive value. It is a String object. Question: What... Core Java Interview Question Page 18  
Core Java Interview Question, Interview Question
instances. Question: What is the difference between the String and StringBuffer... Core Java Interview Question Page 16       Question: Which containers may have a MenuBar
Core Java Interview Question, Interview Question
takes an argument of the String[] type. Question: Which Java operator is right... Core Java Interview Question Page 15       Question: What invokes a thread's run() method
java question - Java Beginners
Java Question What is Public, Static, void and main  Can anyone please explain the meaning of public static and void main in Java?  Public... - is a function to execute (string args[])string - datatypeand args[ ] - use to pass
Core Java Interview Question, Interview Question
in the object are same Question: What would you use to compare two String variables... point at the same instance of a String object Question: Give example... be extended Question: What is the difference between String and StringBuffer
Core Java Interview Question, Interview Question
Core Java Interview Question Page 2       Question: Does it matter... the IOException. Exception's subclasses have to be caught first. Question: Can an inner
ArrayList question plz solve it
ArrayList question plz solve it  An arraylist object stores an Emp... to access the data in the basis of age based? Provide answer to the question with an example..   import java.util.*; class EmployeeData { String
Core Java Interview Question, Interview Question
of unhand led events. Question: How is it possible for two String objects... Core Java Interview Question Page 20       Question: Name four Container classes. Answer
java question related to objects
java question related to objects  what is the output of the following code? public class objComp { Public static void main(String args[]) { Int result = 0; objComp oc= new objComp(); object o = oc; if( o==oc) result =1; if(o
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.