java - Possible to make an array of an array? -


this question has answer here:

is possible make array of array? trying make array of array without duplicates.

for example:

string[] colour ={"blue","blue","red","blue","red","red","orange","yellow","purple","green","blue"}; 

and make new array string[] colour into:

string[] uniquecolour = {"blue","red","orange","yellow","purple","green"} 

using function , without declaring it? cause lets change values of string[] colour , turn

string[] fruits = {"apple","banana","orange","tomato","apple","banana"} 

then without doing or changing else function should create

string[] uniquecolour ={"apple","banana","orange","tomato"} 

does such thing exist? sorry trouble. , i'm new java well.

a thank can contribute or me out.

edit: okay using this: - doorknob's answer

set<string> uniqueset = new hashset<string>(arrays.aslist(colour)); string[] uniquecolours = uniqueset.toarray(new string[0]); 

how try display as:

blue red yellow green purple ect 

instead of [blue,red,yellow,green,purple,etc]

use set remove duplicates:

set<string> uniqueset = new hashset<string>(arrays.aslist(colour)); string[] uniquecolours = uniqueset.toarray(new string[0]); 

to display in way wanted:

for (string s : uniquecolors) system.out.println(s); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -