hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
16 1924
hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
What is your question?!
regards,
sukatoa
hi dere,
i have a question.
i have an array with replicating values.... al i want to do is
delete all replicating values and store the result in another array.
eg.,
String[] a={1,2,3,3};
String []b;
b should be 1.2.3only........not 1,2,3,3
thanks in advance,
regards,
aswath.n.s
(knowledge is power)
... and what have you done so far?
Kind regards
HashSet.
JosAH 11,448
Recognized Expert MVP
(knowledge is power)
I don't think so: knowing what to do with your knowledge may give some power,
otherwise you just have to carry that knowledge around in your brain.
kind regards,
Jos
I don't think so: knowing what to do with your knowledge may give some power,
otherwise you just have to carry that knowledge around in your brain.
kind regards,
Jos
... and to prove that, I wrote some VB.NET code today.(there's a first time for everything).
@Jos surely there's an easier way for that problem?
JosAH 11,448
Recognized Expert MVP
... and to prove that, I wrote some VB.NET code today.(there's a first time for everything).
@Jos surely there's an easier way for that problem?
Erm, I didn't mean to say that when you accidentally know something that you
*have* to exercise that knowledge. Some knowledge can better be forgotten ;-)
kind regards,
Jos
ps. you can also iterate from the right and stop when you hit a letter ...
...
ps. you can also iterate from the right and stop when you hit a letter ...
Yeah I knew that, I just couldn't grasp the syntax for the for loop!!
*hides in a little corner*
JosAH 11,448
Recognized Expert MVP
Yeah I knew that, I just couldn't grasp the syntax for the for loop!!
I consider that a little plus on your side.
*hides in a little corner*
No need to, nobody is perfect. Case closed, this is a Java forum after all.
kind regards,
Jos ( <--- knows nooooothing about Basic ;-)
I consider that a little plus on your side.
No need to, nobody is perfect. Case closed, this is a Java forum after all.
kind regards,
Jos ( <--- knows nooooothing about Basic ;-)
Coming back to the original question then, how would I get this duplicates Snipper to work for primitives as well? - import java.util.Arrays;
-
import java.util.Collection;
-
import java.util.HashSet;
-
public class Snipper<E> {
-
E[] array;
-
public static void main(String[] args) {
-
Integer[] x = {4,4,7};
-
System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x)));
-
}
-
public E[] removeDups(Object o) {
-
Collection<E> c = null;
-
-
if(o instanceof Collection) {
-
c = (Collection<E>)o;
-
}
-
else {
-
try {
-
array = (E[])o;
-
}
-
catch(ClassCastException cCE) {
-
System.out.println("Not supported");
-
-
}
-
}
-
if(c != null) {
-
HashSet<E> s = new HashSet (c);
-
array = (E[])s.toArray();
-
}
-
else if(array != null) {
-
final HashSet<E> s = new HashSet () {
-
{
-
for(E e : array) {
-
add(e);
-
}
-
}
-
};
-
array = (E[])s.toArray();
-
}
-
return array;
-
}
-
}
Coming back to the original question then, how would I get this duplicates Snipper to work for primitives as well? - import java.util.Arrays;
-
import java.util.Collection;
-
import java.util.HashSet;
-
public class Snipper<E> {
-
E[] array;
-
public static void main(String[] args) {
-
Integer[] x = {4,4,7};
-
System.out.println(Arrays.toString(new Snipper<Integer>().removeDups(x)));
-
}
-
public E[] removeDups(Object o) {
-
Collection<E> c = null;
-
-
if(o instanceof Collection) {
-
c = (Collection<E>)o;
-
}
-
else {
-
try {
-
array = (E[])o;
-
}
-
catch(ClassCastException cCE) {
-
System.out.println("Not supported");
-
-
}
-
}
-
if(c != null) {
-
HashSet<E> s = new HashSet (c);
-
array = (E[])s.toArray();
-
}
-
else if(array != null) {
-
final HashSet<E> s = new HashSet () {
-
{
-
for(E e : array) {
-
add(e);
-
}
-
}
-
};
-
array = (E[])s.toArray();
-
}
-
return array;
-
}
-
}
come on frds.....
i said knowledge is power not MY knowledge is powerful...
n'way lets drop this issue...
hi r035198x ,
i used ur code and its working fine.....
however i would relly appricate if u could explain me that... i hope i'm not bothering u...
regards,
aswath ns
(knowledge is power)
come on frds.....
i said knowledge is power not MY knowledge is powerful...
n'way lets drop this issue...
hi r035198x ,
i used ur code and its working fine.....
however i would relly appricate if u could explain me that... i hope i'm not bothering u...
regards,
aswath ns
(knowledge is power)
I didn't think you were going to use it because I thought you had an int[].
Which part do you not understand?
Hey, are you using two accounts?
Hey, are you using two accounts?
she is my college Colleague.. check her mail id if needed frnd.. i posed from her account...
i cannot get u wen u say<E>.. is that some generic terms r wat.. can u plz help me with that.....
regards
she is my college Colleague.. check her mail id if needed frnd.. i posed from her account...
i cannot get u wen u say<E>.. is that some generic terms r wat.. can u plz help me with that.....
regards
You can read all about those here.
wat happened to this forum..
why the Admin's are very hard in their words.
please understand the other people those who are starter, freshers to this language and selected this forum for help.
why cant the experienced people know and understand this and reply to your
help needed people.
no one knows fully and no one is unknown here...
please dont use hard words which will make the subscribers not to visit again
this forum helped me so much..
so i wrote this reply.
Even though this is not the JAVA RELATED REPLY.
regards!!!
well wisher
wat happened to this forum..
why the Admin's are very hard in their words.
please understand the other people those who are starter, freshers to this language and selected this forum for help.
why cant the experienced people know and understand this and reply to your
help needed people.
no one knows fully and no one is unknown here...
please dont use hard words which will make the subscribers not to visit again
this forum helped me so much..
so i wrote this reply.
Even though this is not the JAVA RELATED REPLY.
regards!!!
well wisher
Feedback related messages should be posted in the feedback forum only. If you feel there is an inappropriate response from an Admin (or moderator) you can post your feelings in that forum, stating the inappropriate response of course.
but it will take time to go through the feed back section in their busy schedule.
so i have written here. any way i will post it FEEDBACK section.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: jimjim |
last post by:
Hello,
This is a simple question for you all, I guess .
int main(){
double *g= new double;
*g = 9;
delete g;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
*g =...
|
by: JasonK |
last post by:
I would like to move the Delete button such that it displays one time in the
footer row, rather than on every row. I've seen lots of questions asked on
the subject around the net, but no answer...
|
by: flash |
last post by:
Need hlep to delete array only because all function is ok (inser, sort andsearch)
#include <iostream.h>
//functions prototype
void Insert(int,int);
void Delete(int,int);
int...
|
by: Jon Slaughter |
last post by:
Is it safe to remove elements from an array that foreach is working on?
(normally this is not the case but not sure in php) If so is there an
efficient way to handle it? (I could add the indexes to...
| |
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
I remembered delete is implemented through operator overloading, but I am
not quite clear.
Could anyone recommend some links about how delete is implemented so that
I can...
|
by: subramanian100in |
last post by:
Suppose
class Base
{
public:
virtual ~Test() { ... }
// ...
};
class Derived : public Base
|
by: Oliver Graeser |
last post by:
Hi All,
I do some ensemble averaging calculation that requires me to accumulate
very many distributions which I store in arrays. Basically something like
class AdaptiveNW{
public:
int**...
|
by: dlite922 |
last post by:
I can't believe I haven't come across this in all of my PHP programming (or my brain is currently locked)...I need to delete an array from an array that i'm traversing through with a foreach.
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |