String question

String question

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 Tutorials/Questions & Answers:
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 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
Advertisements
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â
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
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
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  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
Question
Question  Sir, give me a java program to count the number of tokens , given a string and a seperator
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
String  how to add spaces with string functions.?   Hi... { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n
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
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
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
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
*; class ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
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
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
string
string  write a program to accept the string and store the reverse stream into another array and print
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
Question
MysqlConnect{ public static void main(String[] args) { System.out.println("MySQL
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
question
;/html> 2)form2.jsp: <% String name=request.getParameter("name"); String
question
extends JFrame{ public static void main(String[]args){ JFrame
question
; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4
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... StringExample{ public static String removeCharAt(String s, int pos
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
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
Question on pooling
Question on pooling  which server supports pooling?Application server or web server
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
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
This question in Jmeter
This question in Jmeter  hi..i want to send request(xml) 100 times but each time in request xml one element needs to change, otherwise request will be failed since its duplicate

Ads